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

网页内容是用 json 动态生成的,需要怎么爬取?

  •  
  •   ljcarsenal · Oct 30, 2014 · 6961 views
    This topic created in 4401 days ago, the information mentioned may be changed or developed.
    用的是scrapy。根据url爬取的是这个网站的整体框架,然后内容是根据json动态生成的。如果直接请求json的url,会报 非法请求的错误。这种情况下应该怎么爬取?
    10 replies  •  2014-10-31 09:00:07 +08:00
    cdxem713
    cdxem713
    Oct 30, 2014
    1
    json的url是不是有post的数据?
    ljcarsenal
    ljcarsenal
    OP
    Oct 30, 2014
    2
    @cdxem713 现在知道原因了。。请求json时,http的header referer 要和那个框架的url相同。。现在问题来了,怎么动态设置header。。
    xunyu
    xunyu
    Oct 30, 2014
    3
    呵呵,scrapy+ghost.py
    cdxem713
    cdxem713
    Oct 30, 2014
    4
    @ljcarsenal 没用过scrapy不知道呢,一般都可以设置header的吧,形式一般是key-value pair那样的,设置成这个网站的首页地址试试。
    fxbird
    fxbird
    Oct 30, 2014
    5
    用phantomjs试试,它可以获得页面源代码,并且可以用js来操作dom,我也是刚学,用它把post改成get提交一个表单,总是跳到另外一个页
    14
    14
    Oct 30, 2014
    6
    json多好啊,都不需要自己结构化数据了……
    pynix
    pynix
    Oct 30, 2014
    7
    urllib都可以设置的嘛。。
    R4rvZ6agNVWr56V0
    R4rvZ6agNVWr56V0
    Oct 31, 2014
    8
    "会报 非法请求的错误" 多半是因为你没加该加的header啊
    konakona
    konakona
    Oct 31, 2014
    9
    把網頁show出來大夥一看不就明白了
    zhyu
    zhyu
    Oct 31, 2014
    10
    用phantomjs
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1100 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 23:04 · PVG 07:04 · LAX 15:04 · JFK 18:04
    ♥ Do have faith in what you're doing.