메시지 큐 (예 : IronMQ - 전체 공개, IronMQ를 개발자 전도사로 만드는 회사)를 사용하여 URL을 전달할 수 있습니다.
크롤러에서 대기열의 URL을 폴링하고 검색 한 메시지를 기반으로 크롤링합니다.
당신이 연결 예제 (이 안된와 의사이지만 기본적인 생각을한다)를 업데이트 할 수 있습니다합니다 :
from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy.settings import Settings
from scrapy import log
from testspiders.spiders.followall import FollowAllSpider
from iron-mq import IronMQ
mq = IronMQ()
q = mq.queue("scrape_queue")
crawler = Crawler(Settings())
crawler.configure()
while True: # poll forever
msg = q.get(timeout=120) # get messages from queue
# timeout is the number of seconds the message will be reserved for, making sure no other crawlers get that message. Set it to a safe value (the max amount of time it will take you to crawl a page)
if len(msg["messages"]) < 1: # if there are no messages waiting to be crawled
time.sleep(1) # wait one second
continue # try again
spider = FollowAllSpider(domain=msg["messages"][0]["body"]) # crawl the domain in the message
crawler.crawl(spider)
crawler.start()
log.start()
reactor.run() # the script will block here
q.delete(msg["messages"][0]["id"]) # when you're done with the message, delete it
예, 심지어 HTTPS를 사용하여, 그런 걸 생각했다 : // GitHub의 .com/darkrho/scrapy-redis하지만 크롤러 자체를 셀러리 작업으로 실행할 계획이었습니다. 관리하기가 더 쉽다고 생각합니다. 셀러 리 내부에서 실행되는 redis ontop을 폴링하는 것이 clusterfluff에 대한 가능성이 너무 많은지 여부에 관계없이 좀 더 생각해야 할 것입니다. 셀러리를 유지하고 싶은 주된 이유는 작업자를 관리하고 워크 플로를 만드는 많은 도구 (캔버스와 같은) 때문입니다. 원래 질문에 대한 아이디어가 있습니까? – Andres
외부에서 폴링을하는 대신 scrapyd를 보강하는 방법이 있습니다. JSON과 (다른 것) API를 사용하여 작업에 연결하고 작업을 시작/중지 할 수 있습니다. 실행중인 스파이더를 수정하는 대신 일부 서버 풀링을 수행하고 일반 스파이더의 새로운 인스턴스를 시작하십시오? 그런 다음 제 3 자 중재를 피하고 모든 것을 한 지붕 아래 두십시오. 어딘가에 scrapyd에 https://github.com/jrydberg/txgossip의 통합이 완료되었습니다. 제 생각으로 새로운 '일자리'를 주입하여 관리자가 될 수있는 피어싱 용 피어 - 투 - 피어 광대 - 컴퓨터를 만들었습니다. – synthesizerpatel