0

Scrapy 版本 0.19

我正在使用此页面上的代码(使用 scrapyd 一次运行多个 scrapy 蜘蛛)。当我跑步时scrapy allcrawl,我得到了

ScrapyDeprecationWaring: Command's default `crawler` is deprecated and will be removed. Use `create_crawler` method to instantiate crawlers

这是代码:

from scrapy.command import ScrapyCommand
import urllib
import urllib2
from scrapy import log

class AllCrawlCommand(ScrapyCommand):

    requires_project = True
    default_settings = {'LOG_ENABLED': False}

    def short_desc(self):
        return "Schedule a run for all available spiders"

    def run(self, args, opts):
        url = 'http://localhost:6800/schedule.json'
        for s in self.crawler.spiders.list(): #this line raise the warning
            values = {'project' : 'YOUR_PROJECT_NAME', 'spider' : s}
            data = urllib.urlencode(values)
            req = urllib2.Request(url, data)
            response = urllib2.urlopen(req)
            log.msg(response)

如何修复 DeprecationWarning ?

谢谢

4

1 回答 1

1

利用:

crawler = self.crawler_process.create_crawler()
于 2013-10-08T00:50:51.980 回答