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

为何curl取不到内容?

  •  
  •   bigdude · 2012-07-16 16:11:40 +08:00 · 3899 次点击
    这是一个创建于 4324 天前的主题,其中的信息可能已经有所发展或是发生改变。
    各位试试这个 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-07-16 16:21:48 +08:00
    可以。
    >>> print len(content)
    87031
    bigdude
        2
    bigdude  
    OP
       2012-07-16 16:29:33 +08:00
    @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-07-16 16:32:51 +08:00
    bigdude
        4
    bigdude  
    OP
       2012-07-16 16:34:49 +08:00
    抓狂·······
    >>> a=urllib.urlopen('http://brand.tmall.com/azIndexInside.htm?firstLetter=A&prt=1342414752421&prc=5')
    >>> len(a.read())
    0
    bigdude
        5
    bigdude  
    OP
       2012-07-16 16:38:59 +08:00
    @yujnln ok了,必须要带cookie,不带不让抓。
    est
        6
    est  
       2012-07-16 16:44:38 +08:00
    bigdude
        7
    bigdude  
    OP
       2012-07-16 17:32:05 +08:00
    @est 了解了,强制让curl follow这个链接,用-L就行了,搞不懂淘宝为何搞这么多跳转
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2276 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 06:57 · PVG 14:57 · LAX 23:57 · JFK 02:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.