【发布时间】:2013-03-24 17:24:31
【问题描述】:
我正在开发一个下载管理器。在 python 中使用 requests 模块来检查有效链接(并希望链接断开)。 我检查以下链接的代码:
url = 'http://pyscripter.googlecode.com/files/PyScripter-v2.5.3-Setup.exe'
r = requests.get(url, allow_redirects=False) # this line takes 40 seconds
if r.status_code==200:
print("link valid")
else:
print("link invalid")
现在,问题是执行此检查大约需要 40 秒,这是巨大的。 我的问题是我怎样才能加快速度,也许使用 urllib2 或其他东西??
注意:另外,如果我将 url 替换为“http://pyscripter.googlecode.com/files/PyScripter-v2.5.3-Setup.exe”的实际 URL,这需要一秒钟,所以看起来是请求的问题。
【问题讨论】:
标签: python download urllib2 python-requests urllib