|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
刚开始学习爬虫
从网站上爬取一只猫:
import urllib.request
response = urllib.request.urlopen('http://placekitten.com/g/500/600')
img = response.read()
with open('cat -500-600','wb') as f:
f.write(img)
模仿上面这是用urllib.request模块实现的爬图,出错了:
import requests:
url =( 'http://placekitten.com/g/500/600')
img = requests.get(url)
with open('cat -500-600','wb') as f:
f.write(img)
出错了......错在哪里了,还有这两个模块都能实现爬取图片,他们区别在哪里,哪个更好用一点
- import urllib.request
- import requests
- url ='http://placekitten.com/g/500/600'
- response = urllib.request.urlopen(url)
- img = response.read()
- with open('cat-500-600-urllib.jpg', 'wb') as f:
- f.write(img)
- img = requests.get(url).content
- with open('cat-500-600-requests.jpg', 'wb') as f:
- f.write(img)
复制代码
看书
|
|