2011-06-27 28 views
7

Hangileri here anlatıldığı gibi bir komut dosyasından scrapy çalıştırmaya çalışıyorum. this snippet'i kullanarak önerdi, ancak yaptığımda süresiz olarak askıda kalıyor. Bu, sürüm .10; Halen mevcut kararlılıkla uyumlu mu?Script bir komut dosyasından çalıştırılıyor -

+0

: örümcekler için dosyadaki ayarları

for spiderConfig in spiderConfigs: spiderConfig = spiderConfig.copy() # a dictionary similar to the one with global settings above spiderName = spiderConfig.pop('name') # name of the spider is in the configs - i can use the same spider in several instances - giving them different names spiderModuleName = spiderConfig.pop('spiderClass') # module with the spider is in the settings spiderModule = __import__(spiderModuleName, {}, {}, ['']) # import that module SpiderClass = spiderModule.Spider # spider class is named 'Spider' spider = SpiderClass(name = spiderName, **spiderConfig) # create the spider with given particular settings crawlerProcess.queue.append_spider(spider) # add the spider to spider pool 

Örnek Bu soru ve cevap güncellemeye hazır olabilir. İşte [Scrapy'den yeni bir snippet] (http://scrapy.readthedocs.org/en/0.16/topics/practices.html). İşe yarıyor, ama benim için soru şu oluyor: Twisted reaktörünü nasıl durdurup bittiğinde nasıl devam edersiniz? – bahmait

cevap

7
from scrapy import signals, log 
from scrapy.xlib.pydispatch import dispatcher 
from scrapy.crawler import CrawlerProcess 
from scrapy.conf import settings 
from scrapy.http import Request 

def handleSpiderIdle(spider): 
    '''Handle spider idle event.''' # http://doc.scrapy.org/topics/signals.html#spider-idle 
    print '\nSpider idle: %s. Restarting it... ' % spider.name 
    for url in spider.start_urls: # reschedule start urls 
     spider.crawler.engine.crawl(Request(url, dont_filter=True), spider) 

mySettings = {'LOG_ENABLED': True, 'ITEM_PIPELINES': 'mybot.pipeline.validate.ValidateMyItem'} # global settings http://doc.scrapy.org/topics/settings.html 

settings.overrides.update(mySettings) 

crawlerProcess = CrawlerProcess(settings) 
crawlerProcess.install() 
crawlerProcess.configure() 

class MySpider(BaseSpider): 
    start_urls = ['http://site_to_scrape'] 
    def parse(self, response): 
     yield item 

spider = MySpider() # create a spider ourselves 
crawlerProcess.queue.append_spider(spider) # add it to spiders pool 

dispatcher.connect(handleSpiderIdle, signals.spider_idle) # use this if you need to handle idle event (restart spider?) 

log.start() # depends on LOG_ENABLED 
print "Starting crawler." 
crawlerProcess.start() 
print "Crawler stopped." 

GÜNCELLEME:

siz de gerekirse örümcek başına ayarlar bu örneğe bakın:

name = punderhere_com  
allowed_domains = plunderhere.com 
spiderClass = scraper.spiders.plunderhere_com 
start_urls = http://www.plunderhere.com/categories.php? 
+0

Bu [https://gist.github.com/1051117) traceback'i alıyorum. Scrapy projem kazıyıcı olarak adlandırıldı. Sorun bu olabilir mi? – ciferkey

+0

Sanırım sorun bu. Bu gerçek bir projeden. Referansları kazıyıcıya kaldırabilirsiniz. Örümcekler için sadece bazı ayarlara ihtiyacın var. – warvariuc

+0

böylece kazıyıcıya yapılan referansları kaldırdıktan sonra projem için ayarlarımdan nasıl bahsedeceğim? – ciferkey

İlgili konular