scrapy 如何在爬虫回调函数中添加关键字?

hfwmuf9z  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(247)

我在向爬虫添加关键字时遇到了问题。我使用scrapyflaskcrochet。函数为:

@crochet.run_in_reactor
def scrape_with_crochet(req):
    eventual = crawl_runner.crawl(Spider, output_data = output_data,**req)
    eventual.addCallback(finished_scrape,callbackKeywords = {'stash':5})

如何在eventual.addCallback中添加关键字我试过eventual.addCallback(finished_scrape,callbackKeywords = {'stash':5})
eventual.addCallback(finished_scrape,cb_kwargs= {'stash':5}),但似乎都不起作用。

xv8emn3q

xv8emn3q1#

根据文件:
def addCallback(self, callback, *args, **kwargs): (source)
仅添加回调的便捷方法。
产品参数

  • callbackCallable[...,Union[_NextDeferredResultT,Deferred[_NextDeferredResultT]]]
  • *argsobject
  • **kwargsobject

退货

  • Deferred

[_NextDeferredResultT]
这意味着你会像这样添加它:

kwargs = {'stash': 5}

@crochet.run_in_reactor
def scrape_with_crochet(req):
    eventual = crawl_runner.crawl(Spider, output_data = output_data,**req)
    eventual.addCallback(finished_scrape, **kwargs)

相关问题