1
xiaocsl 2018-08-29 21:08:59 +08:00
如果用的不是同一套 cookies 的话,那就是封 IP 了,上代理池吧.
|
2
delectate 2018-08-29 21:43:41 +08:00
通常就是 cookies、refer url、IP,逐个排查。
|
3
einverne 2018-08-30 08:37:20 +08:00
大概是因为给识别出机器人网站给你返回了错误的图片,换个 IP 试试
|
4
simoncc 2018-08-30 09:11:44 +08:00
应该是缺了 refer 头,在 headers 中加上。
|
5
imdong 2018-08-30 09:12:01 +08:00
加上来路就好了,常见的图片防盗链。
Referer |
6
Langjan OP 图片地址 http://bizhi.zhuoku.com/2018/04/25/Bugatti/2019-Bugatti-Chiron-Sport-10.jpg
在这个下 http://www.zhuoku.com/zhuomianbizhi/jing-car/20180425160320(10).htm htm 可以直接访问不用加 referer,在该页面显示图片正常,图片右击新标签页打开也正常 (浏览器打开正常应该不是封 IP 吧) 代码如下返回了错误的图片 import urllib.request import requests import re headers = { 'Host':'www.zhuoku.com', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 'Referer':'http://www.zhuoku.com/zhuomianbizhi/jing-car/20180425160320(10).htm' 'Cookie':'cck_lasttime=1535598582789; cck_count=0; bdshare_firstime=1535598583191' } url = 'http://www.zhuoku.com/zhuomianbizhi/jing-car/20180425160320(10).htm' req = requests.get(url, headers = headers) req.encoding = 'GBK' html = req.text picurl = re.findall(r'<img id="imageview" src="(.*?)"', html)[0] picname = re.findall(r'thumbs/tn_(.*?)"', html)[0] path = 'F:\\PyDowns\\zhuoku\\' + picname urllib.request.urlretrieve(picurl, path) |
7
Langjan OP 打开 20180425160320(10)
request headers 为 GET 20180425160320(10) HTTP/1.1 Host: com Proxy-Connection: keep-alive Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6 其中图片的 request headers 为 GET 2019-Bugatti-Chiron-Sport-10 HTTP/1.1 Host: com Proxy-Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Accept: image/webp,image/apng,image/*,*/*;q=0.8 Referer: 20180425160320(10) Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,zh-TW;q=0.6 (由于论坛回复机制删除了 URL ) |
8
Langjan OP urllib.request.urlretrieve() 函数不能提交 header 信息?
下载图片时(等同直接访问图片地址)就会触发防盗,返回错误的图片 这个方法也是不行 content = requests.get(picurl, headers =headers).content with open('F:\\PyDowns\\zhuoku\\demo.jpg', 'wb') as fp: fp.write(content) |