图片地址
http://bizhi.zhuoku.com/2018/04/25/Bugatti/2019-Bugatti-Chiron-Sport-10.jpg在这个下
http://www.zhuoku.com/zhuomianbizhi/jing-car/20180425160320(10).htmhtm 可以直接访问不用加 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)