Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何阻止Scrapy crawler立即执行?_Python_Web Scraping_Scrapy_Web Crawler - Fatal编程技术网

Python 如何阻止Scrapy crawler立即执行?

Python 如何阻止Scrapy crawler立即执行?,python,web-scraping,scrapy,web-crawler,Python,Web Scraping,Scrapy,Web Crawler,我正在使用Scrapy框架来抓取一些网站。我想在我决定挂国旗后立即停止爬行。在我的管道中,我像这样停止爬虫程序: spider.crawler.engine.close_spider(self, reason='My reason') 它会在我需要的时候停止,但它不会停止执行代码,直到它在connectionpool中剩余的URL上发送请求,我不希望这样。如何立即停止,有没有办法从connectionpool中清除URL 先谢谢你 根据scrapyclose\u spider停止调度新请求,它

我正在使用Scrapy框架来抓取一些网站。我想在我决定挂国旗后立即停止爬行。在我的管道中,我像这样停止爬虫程序:

spider.crawler.engine.close_spider(self, reason='My reason')
它会在我需要的时候停止,但它不会停止执行代码,直到它在connectionpool中剩余的URL上发送请求,我不希望这样。如何立即停止,有没有办法从connectionpool中清除URL

先谢谢你

  • 根据scrapy
    close\u spider
    停止调度新请求,它不会立即停止爬网过程。在您的情况下,close_spider的工作完全符合文档记录

  • 我知道的立即停止爬行的唯一方法是使用
    os.exit
    ,就像这样

  • 根据scrapy
    close\u spider
    停止调度新请求,它不会立即停止爬网过程。在您的情况下,close_spider的工作完全符合文档记录

  • 我知道的立即停止爬行的唯一方法是使用
    os.exit
    ,就像这样