找了一些文章,发现都好麻烦啊!
requests.get(url).headers是个字典,里面有个键’Content-Length’对应的值就是文件大小啊,直接提取出来不就可以了吗?
import requests
url='https://qd.myapp.com/myapp/qqteam/pcqq/PCQQ2019.exe'
r=requests.get(url)
file_size_str=r.headers['Content-Length'] #提取出来的是个数字str
file_size=int(file_size_str)/1024/1024 #把提取出数字str转为int或者float进行运算
print(size,'M')