我正在收集网站列表的统计数据,为了简单起见,我使用了请求.这是我的代码:
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())) )
现在,我希望requests.get
在10秒后超时,这样循环就不会卡住.
这个问题也很有趣,但没有一个答案是干净的.我会悬赏这件事以得到一个好的答案.
我听说也许不使用请求是个好主意,但是我应该如何获得请求提供的好处呢?(元组中的那些)