9-06 4,104 views
python下载图片第一种方式
import requests
#图片地址
imgUrl = 'http://www.abc.om/abc.jpg'
headers = { "Accept":"text/html,application/xhtml+xml,application/xml;",
"Accept-Encoding":"gzip",
"Accept-Language":"zh-CN,zh;q=0.8",
"Referer":"http://www.abc.com/",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"
}
response = requests.get(imgUrl, stream=True,headers=headers)
img=imgUrl.split('/')[-2]
with open('test.jpg','wb') as f:
f.write(response.content)
print("download "+img+'...')