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

scrapy 问题请教!

  •  
  •   xnile · Jun 22, 2018 · 2164 views
    This topic created in 2899 days ago, the information mentioned may be changed or developed.

    要爬的网站的评论是由服务端直接一次生成正文内容和评论,非 ajax 调接口获取。这种情况 scrapy 怎样能做到评论即能分页抓取还能和正文内容关联起来。想到的办法是写两个 spider 分别抓取正文和评论,然后再通过程序,根据贴子 id 关联起来。有没有办法一个 spider 直接搞定,item['content'],item['content'],请教下大家!

    4 replies    2018-06-24 09:35:39 +08:00
    ioiogoo
        1
    ioiogoo  
       Jun 22, 2018
    可以通过 scrapy 的 meta 将信息传递给下一个 callback 处理函数,相当于是多个导航分类下多篇文章,多个评论,网上搜下,很多例子
    xnile
        2
    xnile  
    OP
       Jun 22, 2018
    @ioiogoo 好的,我试试,谢谢!
    congeec
        3
    congeec  
       Jun 23, 2018
    def parse_article(self, response):
    ____item = Item()
    ____yield scrapy.Request(url, meta={'item': item}, callback=self.parse_reviews)

    def parse_reviews(self, response):
    ____item = response.meta['item'] # here be the magic
    xnile
        4
    xnile  
    OP
       Jun 24, 2018 via iPhone
    @congeec 好的,谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 12:23 · PVG 20:23 · LAX 05:23 · JFK 08:23
    ♥ Do have faith in what you're doing.