推荐学习书目
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
15874103329
V2EX  ›  Python

[小白求助] 爬取猫眼 top100,打印显示为空

  •  
  •   15874103329 · Dec 3, 2018 · 3100 views
    This topic created in 2750 days ago, the information mentioned may be changed or developed.
    源代码如下:

    import requests
    from requests.exceptions import RequestException

    def get_one_page(url):
    try:
    response = requests.get(url)
    if requests.status_codes == 200:
    return response.text
    return None
    except RequestException:
    return None

    def main():
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3573.0 Safari/537.36'}
    url = requests.get('https://www.hao123.com/', headers=headers)
    html = get_one_page(url)
    print(html)

    if __name__ == '__main__':
    main()
    6 replies    2018-12-06 08:54:24 +08:00
    F1024
        1
    F1024  
       Dec 3, 2018
    网址都错了啊 兄弟
    hly9469
        2
    hly9469  
       Dec 3, 2018 via iPhone
    @F1024 #1 哈哈哈哈哈哈
    deepdark
        3
    deepdark  
       Dec 3, 2018 via Android
    @F1024 哈哈哈哈哈哈哈哈哈 hao123 还行
    lanqing
        4
    lanqing  
       Dec 4, 2018
    找点教程看看吧
    15874103329
        5
    15874103329  
    OP
       Dec 4, 2018
    额,网址之前是对的,后来换别的网址也是这样,不知道哪里出问题了
    LuJason
        6
    LuJason  
       Dec 6, 2018
    requests.get 请求了两遍,第二遍肯定是 return None 啦
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4542 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 10:08 · PVG 18:08 · LAX 03:08 · JFK 06:08
    ♥ Do have faith in what you're doing.