V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2018-03-17 08:51:14 +08:00 · 4186 次点击
    这是一个创建于 2222 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在爬头条新闻评论时遇到一个奇怪的问题,用 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 条回复    2018-03-17 10:02:48 +08:00
    Telegram
        1
    Telegram  
       2018-03-17 08:55:25 +08:00 via iPhone
    抓 postman 和 py 请求的数据包,比较有啥不同,然后慢慢改
    goofool
        2
    goofool  
       2018-03-17 09:12:42 +08:00 via Android
    UA 问题吧
    limerence12138
        3
    limerence12138  
       2018-03-17 09:17:05 +08:00 via Android
    估计没带 UA
    zw
        4
    zw  
       2018-03-17 09:18:32 +08:00
    如果 UA 是 PC 浏览器,如果没有登录,头条是限制评论显示的,不仅禁评,还不给你看,逼用户装手机 app。。。
    netChen
        5
    netChen  
       2018-03-17 10:02:48 +08:00
    检查一下 cookies 和 user-agent,使用代理 IP,抓取信息的时候一定要带上
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5458 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:03 · PVG 15:03 · LAX 00:03 · JFK 03:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.