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
xnile
V2EX  ›  Python

scrapy 问题请教!

  •  
  •   xnile · 2018-06-22 15:19:22 +08:00 · 1648 次点击
    这是一个创建于 2129 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    4 条回复    2018-06-24 09:35:39 +08:00
    ioiogoo
        1
    ioiogoo  
       2018-06-22 15:51:37 +08:00
    可以通过 scrapy 的 meta 将信息传递给下一个 callback 处理函数,相当于是多个导航分类下多篇文章,多个评论,网上搜下,很多例子
    xnile
        2
    xnile  
    OP
       2018-06-22 16:13:11 +08:00
    @ioiogoo 好的,我试试,谢谢!
    congeec
        3
    congeec  
       2018-06-23 00:37:25 +08:00
    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
       2018-06-24 09:35:39 +08:00 via iPhone
    @congeec 好的,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2372 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:06 · PVG 00:06 · LAX 09:06 · JFK 12:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.