Просто возьмите len() из содержание ответа:
Код: Выделить всё
>>> response = requests.get('https://github.com/')
>>> len(response.content)
51671
Однако это не позволит получить точную длину контента. Например, посмотрите этот код Python:
Код: Выделить всё
import sys
import requests
def proccessUrl(url):
try:
r = requests.get(url)
print("Correct Content Length: "+r.headers['Content-Length'])
print("bytes of r.text : "+str(sys.getsizeof(r.text)))
print("bytes of r.content : "+str(sys.getsizeof(r.content)))
print("len r.text : "+str(len(r.text)))
print("len r.content : "+str(len(r.content)))
except Exception as e:
print(str(e))
#this url contains a content-length header, we will use that to see if the content length we calculate is the same.
proccessUrl("https://stackoverflow.com")
Код: Выделить всё
Correct Content Length: 51504
bytes of r.text : 515142
bytes of r.content : 257623
len r.text : 257552
len r.content : 257606
Подробнее здесь: https://stackoverflow.com/questions/508 ... ulating-it
Мобильная версия