作者ms0561188 (蟑螂吃卤蛋)
看板Python
标题[问题] 图片爬虫无法抓取
时间Mon Jun 12 21:31:35 2017
各位前辈大家好,最近无聊玩玩爬虫,有看到可以将网路图片抓取下来的方法
以下是我主要的程式码
header={
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
response = requests.get('
http://img.ltn.com.tw/Upload/liveNews/BigPic/600_phpNlWIKt.jpg',headers=header)
print response
f = open('block.jpg', 'wb')
shutil.copyfileobj(response.raw,f)
f.close()
确实有response 200,但抓取下来的图片位元组为0,想请教一下各位大大原因,谢谢。
(环境为Pycharm)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.123.92.136
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1497274299.A.774.html
1F:→ zerof: 你前面先 print 掉了啊.... 06/12 21:43
2F:→ zerof: 直接 f.write(response.content) 就好了 06/12 21:44
3F:→ ms0561188: 已解决 感谢楼上的大大!!!! 06/12 21:49
4F:推 coeric: response = requests.get( ...... ,stream=True,....) 06/12 21:53
5F:→ coeric: 多这一行即可 06/12 21:53
6F:→ coeric: 是个黑人....XDDDD 06/12 21:57
7F:→ ms0561188: 谢谢楼上的大大,可以用了 谢谢 06/12 21:58
8F:→ coeric: 因为........我也常干这种事....忘了加这一段 06/12 21:59