【问题标题】:scrapy how to make custom delayscrapy如何进行自定义延迟
【发布时间】:2017-10-05 22:58:57
【问题描述】:

我想进行自定义延迟,因为全局延迟在我的代码中效率低下。

因为我不知道我在这个线程中寻找什么:scrapy is slow (60 pages/min) 我决定最好将其作为一个新问题提出。

基本上我有:

amazon request
API request
API request

如果我使用 DOWNLOAD_DELAY = 1 就像拥有:

amazon request
delay(1)
API request
delay(1)
API request
delay(1)

当我实际上只需要:

amazon request
API request
delay(1)
API request
delay(1)

如何实现延迟?我不认为scrapy有这个功能。

【问题讨论】:

  • 检查this,以后可能会提供支持。

标签: python web-scraping scrapy web-crawler


【解决方案1】:

您可以在 python 中使用 time 模块中的 sleep 功能。 https://docs.python.org/2/library/time.html.

它的参数是以秒为单位的,所以代码会去:

from time import sleep
amazon request
API request
sleep(1)
API request
sleep(1)

【讨论】:

  • 人们说你不应该在 scrapy 中使用 sleep:stackoverflow.com/questions/21171239/… "Scrapy 是一个基于 Twisted 的 Python 框架。所以,永远不要在其中使用 time.sleep 或 pause.until!而是尝试使用 Deferred () 来自 Twisted。”
猜你喜欢
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
  • 2019-10-29
  • 1970-01-01
  • 2013-02-07
  • 1970-01-01
  • 1970-01-01
  • 2023-02-11
相关资源
最近更新 更多