爬取 zealer 的的图可以,但爬 Apple 官网的图失败?是被反爬了,需要进行伪装? 1 import urllib2 2 req = urllib2.urlopen('https://www.apple.com/cn/iphone-x/') 3 buf = req.read() 4 5 import re 6 listurl = re.findall(r'https:.+.jpg',buf) 7 print listurl 8 9 10 i = 0 11 for url in listurl: 12 f = open(str(i)+'.jpg',"wb") 13 req = urllib2.urlopen(url) 14 buf = req.read() 15 f.write(buf) 16 i = i+1 ~
1
coderluan 2017-10-07 11:48:45 +08:00
需要进行伪装,先加 header 和 cookie,不行再上代理试试
|
2
crab 2017-10-07 11:49:39 +08:00
Apple 官网应该没反爬虫,只是 http 请求协议头严格些。
|
3
windfarer 2017-10-07 11:52:22 +08:00 via Android
记得加 referer
|