我在 python 2.7 中使用 scrapy 0.20
我想避免重复的项目。
我不想在命令行中使用 JOBDIR
作为参数。相反,我在我的脚本中这样做:
settings.overrides['JOBDIR']= 'my customer jobdir'
然后我在我的设置中这样做:
DUPEFILTER_CLASS = 'MyProject.CustomFilter.CustomFilter'
并且在 CustomFilter
中我起诉了这个:
def request_seen(self, request):
fp = self.__getid(request.url)
if (fp is not None) and (fp in self.fingerprints):
return True
elif fp is not None:
self.fingerprints.add(fp)
if self.file:
self.file.write(fp + os.linesep)
else:
return False
其中 __getid
是我使用的辅助函数。
我的问题
蜘蛛在找到第一个重复项时停止工作。
我在 CMD 上发现了这条消息:
2014-03-03 10:43:44-0800 [GeneralSpider] DEBUG: Filtered duplicate request: <GET
http://www.justproperty.com/apartments/old-town/1057362-most-affordable-2-b-r-i
n-old-town-for-sale.html> - no more duplicates will be shown (see DUPEFILTER_CLA
SS)
最佳答案
您可以在请求调用中使用参数 dont_filter=True
。这将指示 scrapy 不要忽略重复的请求。已记录 here
关于python - scrapy 蜘蛛停在第一个重复的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22154886/