Skip to main content
 首页 » 编程设计

python之抓取网站时出现错误 "Took longer than 180.0 seconds"。为什么

2025年05月04日19dudu

当我运行脚本时,scrapy 不断抛出此消息:

Took longer than 180.0 seconds 

出现这个问题的原因是什么,有什么具体的解决办法吗?

这是此消息的屏幕截图。

请您参考如下方法:

您在下载时遇到了 scrapy 超时。

参见 DOWNLOAD_TIMEOUT

默认为 360 秒 = 6 分钟。调整您的设置以使其更长。

根据文档你的设置

can be populated using different mechanisms, each of which having a different precedence. Here is the list of them in decreasing order of precedence:

Command line options (most precedence)
Settings per-spider
Project settings module
Default settings per-command
Default global settings (less precedence)

你没有分享你的代码,所以很难说,但是你要么修改你的蜘蛛的设置,要么将它们作为命令行选项提供。

scrapy crawl myspider -s DOWNLOAD_TIMEOUT=<some value that benefits you crawling> 

或者你可以像这样为每个蜘蛛设置它们:

class MySpider(scrapy.Spider): 
    name = 'myspider' 
 
    custom_settings = { 
        'DOWNLOAD_TIMEOUT': 'some value', 
    } 

有关更多信息,请阅读 the settings-manual