相关疑难解决方法(0)

python中urllib的响应时间

我希望在使用时获得响应时间urllib.我在下面编写代码,但它不仅仅是响应时间.我可以花时间使用urllib或有其他方法吗?

import urllib
import datetime

def main():
    urllist = [
        "http://google.com",
    ]

    for url in urllist:
        opener = urllib.FancyURLopener({})
        try:
            start = datetime.datetime.now()
            f = opener.open(url)
            end = datetime.datetime.now()
            diff = end - start
            print int(round(diff.microseconds / 1000))
        except IOError, e:
            print 'error', url
        else:
            print f.getcode(), f.geturl()

if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

python urllib

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×1

urllib ×1