推荐学习书目
› 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 · 7334 views
    This topic created in 3781 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
    hebwjb
    Jul 9, 2016❤️1
    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
    sparkssssssss
    Jul 9, 2016
    2
    加个 headers 就可以了把
    nlimpid
    nlimpid
    OP
    Jul 9, 2016
    3
    @hebwjb 感谢,但是为什么呢?
    zwh8800
    zwh8800
    Jul 9, 2016
    4
    @nlimpid 一般网站都会检查 ua
    GreatMartial
    GreatMartial
    Jul 9, 2016
    5
    @nlimpid 有的网站要检查你的请求环境,你不模拟,就认定你是机器
    CosimoZi
    CosimoZi
    Jul 9, 2016
    6
    知乎现在防爬虫越来越严格了……之前我爬还不需要 headers 就能上。
    tobacco
    tobacco
    Jul 9, 2016
    7
    有现成的知乎爬虫: https://github.com/egrcc/zhihu-python
    nlimpid
    nlimpid
    OP
    Jul 10, 2016
    8
    @tobacco 感谢,但我不是想做爬虫。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2613 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 04:34 · PVG 12:34 · LAX 20:34 · JFK 23:34
    ♥ Do have faith in what you're doing.