您可以使用time模块的sleep函数来实现每隔2秒发送一次http请求。下面是一个示例代码:

import time
import requests

def send_http_request():
    # 发送http请求的代码
    response = requests.get('http://example.com')
    print(response.text)

while True:
    send_http_request()
    time.sleep(2)

在上面的代码中,send_http_request函数是发送http请求的代码,可以根据您的实际需求进行修改。在主循环中,调用send_http_request函数发送http请求,然后使用time.sleep(2)暂停2秒,再次发送下一次请求。这样就实现了每隔2秒发送一次http请求的功能。

for循环每隔2秒发送一次http请求

原文地址: https://www.cveoy.top/t/topic/hyrH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录