网络编程
位置:首页>> 网络编程>> Python编程>> python获取文件真实链接的方法,针对于302返回码

python获取文件真实链接的方法,针对于302返回码

作者:AdgerZhou  发布时间:2023-11-23 04:31:03 

标签:python,文件,真实,链接,302

使用模块requests

方式代码如下:


import requests
url_string="https://******"
r = requests.head(url_string, stream=True)
print r.headers['Location']

扩展:

设置属性:allow_redirects = True ,则head方式会自动解析重定向链接,requests.get()方法的allow_redirects默认为True,head方法默认为False


url_string="https://******"
r = requests.head(url_string, stream=True, allow_redirects=True)
# print r.headers['Location']
print r.headers["Content-Length"]

使用requests.get()方法,该方法会自动解析重定向的链接.

实例:


import requests
url_string="https://******"
r = requests.get(url_string, stream=True)
print r.headers["Content-Length"]

来源:https://blog.csdn.net/qq_18863573/article/details/67632538

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com