我使用scrapy splash从Javascript驱动的IFRAMEd页面中提取信息。有时,我的splash Javascript函数会因为某些浏览器条件而失败,并返回一条错误消息(如{"error": "NotSupportedError: DOM Exception 9"})。
在我的项目管道中,我删除了这些项目,以保持结果的整洁:
class NewspaperLayoutPipeline(object):
def process_item(self, item, spider):
if item.has_key('error'):
raise DropItem("Error capturing item %s" % item)
...不幸的是,我的错误率大约是40%。因此,我想让scrapy-splash重试这些失败的urls,而不是简单地删除项目。我该怎么做呢?
发布于 2017-03-01 18:24:57
不能在Pipeline中重试项目。
你应该在你的爬虫中写一个检查,然后再次yield Request(url, dont_filter=True)相同的网址。
def parse(self, response):
if item.has_key('error'):
raise DropItem("Error capturing item %s" % item)
yield Request(response.url, dont_filter=True)https://stackoverflow.com/questions/42519442
复制相似问题