我正在使用 scrapy 从成员(member)专用网站上抓取数据。我成功执行登录并抓取数据。
但是,我现在需要在数据抓取完成后在网站上提交一些表单。即:在读取所有数据之后,我想将一些数据写入我正在从中抓取(读取)数据的站点。
我的问题是:
我如何得知 scrapy 已完成处理所有网址抓取,以便我可以执行一些表单提交?
我注意到一个解决方案 - 请参阅此处( scrapy: Call a function when a spider quits ),但由于某种原因,我无法继续在 self.spider_close 方法中产生更多请求,因为它在这些示例上被调用,因此我可以执行一些写入操作。
最佳答案
是的,在发出 spider_close
信号后,您无法继续使用蜘蛛 - 为时已晚,蜘蛛此时已经关闭。
更好的信号是 spider_idle
:
Sent when a spider has gone idle, which means the spider has no further:
- requests waiting to be downloaded
- requests scheduled
- items being processed in the item pipeline
关于python - scrapy:在scrapy整理处理url后发布一些表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632717/