Coder Social home page Coder Social logo

Comments (3)

Insutanto avatar Insutanto commented on May 27, 2024

一般这种情况是由单独的脚本写数据到队列中。
如果是使用rabbitmq作为队列,我自己写爬虫的时候是这么加的。

from scrapy.http.request import Request
from scrapy_distributed.queues.common import BytesDump, keys_string
from scrapy_distributed.queues.amqp import RabbitQueue

if __name__ == "__main__":
    _queue: RabbitQueue = RabbitQueue.from_queue_conf("amqp://guest:guest@localhost:5672/?heartbeat=0", YourSpider.queue_conf)
    body = json.dumps(keys_string(RabbitQueue._request_to_dict(Request(url=your_url), YourSpider())), cls=BytesDump)
    _queue.channel.basic_publish(exchange="", routing_key=_queue.name, body=body, properties=BasicProperties(delivery_mode=2))

后续可以考虑封装起来。

from scrapy-distributed.

zhouboboya avatar zhouboboya commented on May 27, 2024

这样的话,1、start_requests方法 是不是就没有用了,或者说起始的url 为空, 任务会自动从队列中加载这样的逻辑?

我得想法2、是在sitemap.py 中模仿scrapy_redis实现一个类似RabbitMixin的方法,和scrapy_redis那样的逻辑就行了,您看这样可以吗?

from scrapy-distributed.

Insutanto avatar Insutanto commented on May 27, 2024

这样的话,1、start_requests方法 是不是就没有用了,或者说起始的url 为空, 任务会自动从队列中加载这样的逻辑?

我得想法2、是在sitemap.py 中模仿scrapy_redis实现一个类似RabbitMixin的方法,和scrapy_redis那样的逻辑就行了,您看这样可以吗?

用 start_requests 也是可以的。
如果是用sitemap爬虫,初始URL是从 sitemap_urls 取,和 scrapy 自带的 sitemap 爬虫一样。

from scrapy-distributed.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.