2 回答

TA贡献1816条经验 获得超6个赞
根据Common Practices和API 文档,您应该crawl像这样调用方法将参数传递给蜘蛛构造函数:
process = CrawlerProcess(get_project_settings())
process.crawl(SpiderTest1, url, variable_1, variable_2)
process.start()
更新: 文档还提到了这种运行蜘蛛的形式:
process.crawl('followall', domain='scrapinghub.com')
在本例中,'followall'是项目中蜘蛛的名称(即name蜘蛛类的属性值)。在您定义蜘蛛的特定情况下,如下所示:
class SpiderTest1(scrapy.Spider):
name = 'main run'
...
您将使用此代码使用蜘蛛名称运行您的蜘蛛:
process = CrawlerProcess(get_project_settings())
process.crawl('main run', url, variable_1, variable_2)
process.start()

TA贡献1797条经验 获得超4个赞
谢谢,我的代码按照你的方式工作正常。但我发现事情与常见做法略有不同
这是我们的代码:
process.crawl(SpiderTest1, url, variable_1, variable_2)
这是来自Common Practices
process.crawl('followall', domain='scrapinghub.com')
您建议的第一个变量是使用 class's name SpiderTest1
,但另一个使用 string'followall'
什么是'followall'
指什么?它指的是目录:testspiders/testspiders/spiders/followall.py
或只是类的变量name = 'followall'
下followall.py
我问它是因为我仍然很困惑什么时候应该打电话string
或class name
在scrapy蜘蛛中。
谢谢。
添加回答
举报