随着时间的推移递归递归回调
我想刮擦一个网站,该网站每5分钟删除给定网页的信息。我通过在递归回调之间添加5分钟的睡眠时间来实现这一点,但是
def _parse(self, response):
status_loader = ItemLoader(Status())
# perform parsing
yield status_loader.load_item()
time.sleep(5)
yield scrapy.Request(response._url,callback=self._parse,dont_filter=True,meta=response.meta)
,将时间添加时间 。出于某种原因,废纸确实发送了请求,但是收益项并未(或很少)输出到给定的输出文件。
我当时认为这与废弃的请求优先级有关,这可能优先于发送新请求而不是产生刮擦物品。会这样吗?我试图编辑设置,从深度优先的队列转到广度优先的队列。这无法解决问题。
我如何在给定的时间间隔刮擦网站,假设5分钟?
I want to scrape a website which scrapes information of given webpages every 5 minutes. I implemented this by adding a sleep time of 5 minutes in between a recursive callback, like so:
def _parse(self, response):
status_loader = ItemLoader(Status())
# perform parsing
yield status_loader.load_item()
time.sleep(5)
yield scrapy.Request(response._url,callback=self._parse,dont_filter=True,meta=response.meta)
However, adding time.sleep(5) to the scraper seems to mess with the inner workings of scrapy. For some reason scrapy does send out the request, but the yield items are not (or rarely) outputted to the given output file.
I was thinking it has to do with the request prioritization of scrapy, which might prioritize sending a new request over yielding the scraped items. Could this be the case? I tried to edit the settings to go from a depth-first queue to a breadth-first queue. This did not solve the problem.
How would I go about scraping a website at a given interval, let's say 5 minutes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它行不通,因为
scrapy
默认情况下是异步的。尝试设置这样的玉米作业 -
根据您正在使用的
OS
,这将每5分钟运行您所需的蜘蛛It won't work because
Scrapy
is asynchronous by default.Try to set a corn job like this instead -
This will run your desired spider every 5 mins depending on the
os
you are using