推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
nlimpid
V2EX  ›  Python

求助,为什么 Requests 不能获取到知乎的页面?

  •  
  •   nlimpid ·
    nlimpid · Jul 9, 2016 · 7216 views
    This topic created in 3732 days ago, the information mentioned may be changed or developed.
    >>> requests.get("http://github.com")
    <Response [200]>
    >>> requests.get("https://github.com")
    <Response [200]>
    >>> requests.get("https://www.baidu.com")
    <Response [200]>
    >>> requests.get("http://zhihu.com")
    <Response [500]>
    >>> requests.get("https://zhihu.com")
    <Response [500]>

    但是用 urlopen 可以,不知道为什么,求解。
    8 replies  •  2016-07-10 19:25:27 +08:00
    hebwjb
        1
    hebwjb  
       Jul 9, 2016   ❤️ 1
    header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"}

    requests.get('http://zhihu.com',headers=header)
    <Response [200]>
    sparkssssssss
        2
    sparkssssssss  
       Jul 9, 2016
    加个 headers 就可以了把
    nlimpid
        3
    nlimpid  
    OP
       Jul 9, 2016
    @hebwjb 感谢,但是为什么呢?
    zwh8800
        4
    zwh8800  
       Jul 9, 2016
    @nlimpid 一般网站都会检查 ua
    GreatMartial
        5
    GreatMartial  
       Jul 9, 2016
    @nlimpid 有的网站要检查你的请求环境,你不模拟,就认定你是机器
    CosimoZi
        6
    CosimoZi  
       Jul 9, 2016
    知乎现在防爬虫越来越严格了……之前我爬还不需要 headers 就能上。
    tobacco
        7
    tobacco  
       Jul 9, 2016
    有现成的知乎爬虫: https://github.com/egrcc/zhihu-python
    nlimpid
        8
    nlimpid  
    OP
       Jul 10, 2016
    @tobacco 感谢,但我不是想做爬虫。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2791 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 14:26 · PVG 22:26 · LAX 07:26 · JFK 10:26
    ♥ Do have faith in what you're doing.