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

为何curl取不到内容?

  •  
  •   bigdude · 2012 年 7 月 16 日 · 4246 次点击
    这是一个创建于 4940 天前的主题,其中的信息可能已经有所发展或是发生改变。
    各位试试这个 curl "http://brand.tmall.com/azIndexInside.htm?firstLetter=A&prt=1342414752421&prc=5" 能否取到内容。

    初步研究貌似跟referer、useragent等无关。
    7 条回复    1970-01-01 08:00:00 +08:00
    yujnln
        1
    yujnln  
       2012 年 7 月 16 日
    可以。
    >>> print len(content)
    87031
    bigdude
        2
    bigdude  
    OP
       2012 年 7 月 16 日
    @yujnln 你用的python?我用urllib2老是告诉我
    urllib2.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
    The last 30x error message was:
    Moved Temporarily
    yujnln
        3
    yujnln  
       2012 年 7 月 16 日
    bigdude
        4
    bigdude  
    OP
       2012 年 7 月 16 日
    抓狂·······
    >>> a=urllib.urlopen('http://brand.tmall.com/azIndexInside.htm?firstLetter=A&prt=1342414752421&prc=5')
    >>> len(a.read())
    0
    bigdude
        5
    bigdude  
    OP
       2012 年 7 月 16 日
    @yujnln ok了,必须要带cookie,不带不让抓。
    est
        6
    est  
       2012 年 7 月 16 日
    bigdude
        7
    bigdude  
    OP
       2012 年 7 月 16 日
    @est 了解了,强制让curl follow这个链接,用-L就行了,搞不懂淘宝为何搞这么多跳转
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1226 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 17:50 · PVG 01:50 · LAX 09:50 · JFK 12:50
    ♥ Do have faith in what you're doing.