是的,Python 的 time.sleep() 函数可以用于网络请求之间的延迟
例如,使用 requests 库发送多个网络请求并在每个请求之间添加延迟:
import requests
import time
url = "https://api.example.com/data"
for i in range(5):
response = requests.get(url)
print(response.json())
time.sleep(2) # 等待 2 秒
在这个例子中,我们向 https://api.example.com/data 发送了 5 个请求,每次请求之间暂停了 2 秒。