相关疑难解决方法(0)

python requests.get超时的完成响应

我正在收集网站列表的统计数据,为了简单起见,我正在使用它的请求.这是我的代码:

data=[]
websites=['http://google.com', 'http://bbc.co.uk']
for w in websites:
    r= requests.get(w, verify=False)
    data.append( (r.url, len(r.content), r.elapsed.total_seconds(), str([(l.status_code, l.url) for l in r.history]), str(r.headers.items()), str(r.cookies.items())) )
Run Code Online (Sandbox Code Playgroud)

现在,我希望requests.get在10秒后超时,这样循环就不会卡住.

这个问题之前也引起了人们的兴趣,但没有一个答案是清晰的.我将在此给予一些赏金以获得一个很好的答案.

我听说也许不使用请求是一个好主意,但那么我应该如何获得请求提供的好东西.(元组中的那些)

python timeout python-requests

134
推荐指数
11
解决办法
18万
查看次数

标签 统计

python ×1

python-requests ×1

timeout ×1