1
我已经创建了一个测试蜘蛛。该蜘蛛获得一个具有url
和xpath
属性的对象。它会擦除url
,然后相应地填充self.result
字典。所以self.result
可以{'success':True,'httpresponse':200}
或{'success':False,'httpresponse':404}
等如何在爬网后访问蜘蛛属性
的问题是,我不知道如何访问spider.result
因为没有对象的蜘蛛。
..
def test(self):
from scrapy.crawler import CrawlerProcess
ts = TestSpider
process = CrawlerProcess({...})
process.crawl(ts,[object,])
process.start()
print ts.result
我想:
def test(self):
from scrapy.crawler import CrawlerProcess
ts = TestSpider(object)
process = CrawlerProcess({...})
process.crawl(ts)
process.start()
print ts.result
但它说,爬需要2个参数。
你知道该怎么做吗?我不想将结果保存到文件或数据库中。
'CrawlerProcess.crawl'需要蜘蛛类的说法,你是通过一个蜘蛛对象。可以解释一个用例吗?这似乎不必要复杂 – Granitosaurus
您可以尝试'process.crawlers [0] .spider.result',但可能更优雅的解决方案 – Granitosaurus
您可以使用logging.INFO – parik