【问题标题】:Scrapy: best way to select urls based on mysqlScrapy:基于 mysql 选择 url 的最佳方法
【发布时间】:2013-02-28 01:34:04
【问题描述】:
我制作了一个从论坛线程中收集一些数据的 Scrapy 爬虫。在列表页面上,我可以看到最后修改日期。
根据那个日期,我想决定是否再次抓取线程。我使用管道将数据存储在mysql中。在使用我的 CrawlSpider 处理列表页面时,我想检查 mysql 中的记录,并根据该记录我想产生或不产生请求。 (除非有新帖子,否则我不想加载网址。)
最好的方法是什么?
【问题讨论】:
标签:
python
mysql
web-crawler
scrapy
【解决方案1】:
使用CrawSpiderRule:
Rule(SgmlLinkExtractor(), follow=True, process_request='check_moddate'),
然后在你的蜘蛛中:
def check_moddate(self, request):
def dateisnew():
# check the date
if dateisnew():
return request