Узнать время скачивания картинки, пользуясь requests библиотекой или иной

Рейтинг: 1Ответов: 1Опубликовано: 26.03.2015

В общем, нужно узнать время скачивания картинки. Сохраняю картинки с помощью такого кода:

 import requests

 link = http://www.mysite.ru/images/hello.jpg'

 out = open('/home/alexey/Projects/images/goods/hello.jpg', 'w')

 p = requests.get(link)

 out.write(p.content)

 out.close()

Может, кто знает другой метод сохранения или же с использованием этой бибилотеки, но главное узнать время скачивания изображения? Мне это нужно, для того чтобы задать имя картинки в unix timestamp в дальнейшем.

Ответы

▲ 1

print p.elapsed

elapsed - The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the stream keyword argument. http://docs.python-requests.org/en/latest/api/?highlight=elapsed#requests.Response.elapsed