如何从文件URL获取内容长度?

时间:2018-08-07 16:20:00

标签: python-3.x request

我想使用请求从文件URL提取内容长度,但是如果不下载文件就无法这样做。我用过requests.getrequests.head

url = 'http://www.example.com'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}

r = requests.head(url)
filename = r.headers
print(filename)

响应为

{'Date': 'Tue, 07 Aug 2018 15:19:05 GMT', 'Content-Type': 'text/plain; charset=utf-8', 'Connection': 'keep-alive', 'Set-Cookie': '__cfduid=d3f062f59c1c1c8a1c492c86ad4b139451533655145; expires=Wed, 07-Aug-19 15:19:05 GMT; path=/; domain=.apkmonk.com; HttpOnly', 'Vary': 'Origin', 'X-Amz-Request-Id': '1548A33AA7546D9A', 'Server': 'cloudflare', 'CF-RAY': '446ab830e3348963-MAA', 'Content-Encoding': 'gzip'}

使用requestss.get,它首先开始下载。

0 个答案:

没有答案