三种方式简单爬取图片

import urllib.request
url='http://pic1.win4000.com/wallpaper/2017-11-07/5a017d438ae32.jpg'
# 第一种方式
response = urllib.request.urlopen(url)

with open('11.jpg', 'wb') as fp:
    fp.write(response.read())

# 第二种方式
# url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1540207707807&di=65cc0cc694828000e7cb7d1ba4a41f05&imgtype=jpg&src=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D1237387429%2C1290845224%26fm%3D214%26gp%3D0.jpg'
# urllib.request.urlretrieve(url, 'mengjie.jpg')
import requests
response=requests.get('http://pic1.win4000.com/wallpaper/2018-03-20/5ab0bf18db327.jpg')
print(response.content)#抓取图片把text换成content
with open('00000000001.jpg','wb')as f:#w+ :检测文件不存在,自动创建,encoding解码
    f.write(response.content)

 

posted @ 2018-12-17 20:06  青春叛逆者  阅读(619)  评论(0编辑  收藏  举报