V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
TechF1x
V2EX  ›  问与答

Python 爬虫

  •  
  •   TechF1x · 2017-10-07 11:34:30 +08:00 · 1565 次点击
    这是一个创建于 2398 天前的主题,其中的信息可能已经有所发展或是发生改变。

    爬取 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 ~

    5 条回复    2017-10-07 11:56:32 +08:00
    coderluan
        1
    coderluan  
       2017-10-07 11:48:45 +08:00
    需要进行伪装,先加 header 和 cookie,不行再上代理试试
    crab
        2
    crab  
       2017-10-07 11:49:39 +08:00
    Apple 官网应该没反爬虫,只是 http 请求协议头严格些。
    windfarer
        3
    windfarer  
       2017-10-07 11:52:22 +08:00 via Android
    记得加 referer
    TechF1x
        4
    TechF1x  
    OP
       2017-10-07 11:56:00 +08:00
    @coderluan ok,谢谢,试试
    TechF1x
        5
    TechF1x  
    OP
       2017-10-07 11:56:32 +08:00
    @windfarer 好的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2102 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:55 · PVG 09:55 · LAX 18:55 · JFK 21:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.