I want to get response time when I use urllib
. I made below code, but it is more than response time. Can I get the time using urllib
or have any other method?
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()