V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
capljf
V2EX  ›  Python

头条新闻评论爬虫,返回信息为空的奇怪现象

  •  
  •   capljf · Mar 17, 2018 · 5015 views
    This topic created in 2963 days ago, the information mentioned may be changed or developed.

    我在爬头条新闻评论时遇到一个奇怪的问题,用 postman 模拟请求可以正常获得数据, 但用 python requests 模块写的请求获取到的数据总是空的,有返回信息,但里面没有有用的价值。 接口类似于这种: https://www.toutiao.com/api/comment/list/?group_id=6533396129860551182&item_id=6533396129860551182

    postman 返回数据: { message: "success", data: { has_more: true, total: 65, comments: [ { text: "充电一回,能用半年,我们就买。", digg_count: 293, reply_data: { reply_list: [ ] }, ....省略很多}

    python 程序返回数据: {"message": "success", "data": { "has_more": false, "total": 0, "comments": []}}

    5 replies    2018-03-17 10:02:48 +08:00
    Telegram
        1
    Telegram  
       Mar 17, 2018 via iPhone
    抓 postman 和 py 请求的数据包,比较有啥不同,然后慢慢改
    goofool
        2
    goofool  
       Mar 17, 2018 via Android
    UA 问题吧
    limerence12138
        3
    limerence12138  
       Mar 17, 2018 via Android
    估计没带 UA
    zw
        4
    zw  
       Mar 17, 2018
    如果 UA 是 PC 浏览器,如果没有登录,头条是限制评论显示的,不仅禁评,还不给你看,逼用户装手机 app。。。
    netChen
        5
    netChen  
       Mar 17, 2018
    检查一下 cookies 和 user-agent,使用代理 IP,抓取信息的时候一定要带上
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6076 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 78ms · UTC 02:36 · PVG 10:36 · LAX 19:36 · JFK 22:36
    ♥ Do have faith in what you're doing.