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

Tornado+scrapy(Twisted) 框架结合 0, 支持 newrelic 服务器监控 1, 异步非阻塞 2, realtime 实时响应(不经过任何数据库存储)

  •  
  •   forgetTb · 2018-05-16 10:17:08 +08:00 · 2630 次点击
    这是一个创建于 2143 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有谁处理处理过 Tornado+scrapy(Twisted) 框架结合吗?目前在参考( http://www.tornadoweb.org/en/stable/twisted.html#twisted-on-tornado
    主要目标:
    0, 支持 newrelic 服务器监控
    1, 异步非阻塞
    2,realtime 实时响应(不经过任何数据库存储)
    选择 Tornado 是因为支持 newrelic,这是主要原因,还有异步
    Twisted 也是异步非阻塞。

    以下方案我也参考过
    scrapyDO, 已经被改造成阻塞(如 flask+scrapy 都是如此)
    scrapyrt(modify)( https://github.com/haijunt/scrapyrt), 支持 realtime,不支持 newrelic
    arachnado ( https://github.com/TeamHG-Memex/arachnado)

    其他
    pyspider 正在考虑研究。
    9 条回复    2018-06-20 20:05:10 +08:00
    forgetTb
        1
    forgetTb  
    OP
       2018-05-16 10:42:22 +08:00
    或者说能够使用 tornado.platform.twisted
    具体是在 Tornado 框架下
    import tornado.platform.twisted
    tornado.platform.twisted.install()
    from twisted.internet import reactor

    调用 Scrapy 启动爬虫(EvenvLoop 事件循环的代码)
    dfd = process.crawl(QuotesSpider)
    # process.start() # the script will block here until the crawling is finished d.addBoth(lambda _: reactor.stop())
    result = dfd.addCallback(self.result_items)
    并且直接拿到爬取数据。

    参考链接如下:
    https://stackoverflow.com/questions/36384286/how-to-integrate-flask-scrapy
    http://www.tornadoweb.org/en/stable/twisted.html#twisted-on-tornado
    https://doc.scrapy.org/en/latest/topics/practices.html
    crb912
        2
    crb912  
       2018-05-16 12:09:03 +08:00 via Android
    原理是:Twisted 建立连接和请求,scrapy 分析数据,tornado 显示?
    golmic
        3
    golmic  
       2018-05-16 12:40:55 +08:00 via Android
    不知道目的是什么。我的做法是解耦,scrapy 只管并发抓取的事
    chrisyunhua
        4
    chrisyunhua  
       2018-05-16 17:49:10 +08:00
    pyspider rpc 调用挺好的
    forgetTb
        5
    forgetTb  
    OP
       2018-05-18 10:20:50 +08:00
    @crb912 Tornado 做 webserver (可以用 newrelic 做服务器监控), 调用 scrapy 项目的爬虫并实时响应返回。( scrapyrt 是用 Twisted 做 Webserver:不能够与 newrelic 搭配使用 XXX )
    forgetTb
        6
    forgetTb  
    OP
       2018-05-18 10:24:43 +08:00
    @golmic 1, 需要的是实时响应,类似 scrapyrt(realtime, nonblocking)这种。但 scrapyrt 是使用 Twisted 做 WebServer,并不能与 newrelic(:一种服务器监控软件)搭配使用。现在想使用 Tornado 做 WebServer(支持 newrelic,且异步)。
    golmic
        7
    golmic  
       2018-05-18 14:20:51 +08:00
    我没太懂啊,实时响应的意思是前端传一个 URL,爬虫马上去抓取然后返回结果给 client ?那这过程不是同步的么?
    kmz
        8
    kmz  
       2018-05-29 15:22:01 +08:00
    请问楼主有没有新进展?我也想做类似的
    kmz
        9
    kmz  
       2018-06-20 20:05:10 +08:00
    我初步完成了,,,https://www.v2ex.com/t/464495
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3035 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:53 · PVG 22:53 · LAX 07:53 · JFK 10:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.