python获取文件真实链接的方法,针对于302返回码
作者:AdgerZhou 时间:2023-11-23 04:31:03
使用模块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
标签:python,文件,真实,链接,302
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP安全的URL字符串base64编码和解码
2023-09-06 22:04:45
分享20个数据库设计的最佳实践
2024-01-24 09:28:53
web标准:CSS clear的属性及使用方法
2008-10-27 13:31:00
JS实现页面打印(整体、局部)
2024-04-26 17:14:27
Python中logging日志的四个等级和使用
2023-05-10 14:57:41
![](https://img.aspxhome.com/file/2023/8/76688_0s.png)
Python中的int函数使用
2023-05-13 06:11:59
python实现数据结构中双向循环链表操作的示例
2023-09-05 00:36:47
asp如何做一个随机密码产生器?
2010-07-12 18:57:00
Golang并发利器sync.Once的用法详解
2024-04-25 15:12:06
Python 获取当前所在目录的方法详解
2021-07-19 09:41:14
vue中英文切换实例代码
2024-05-29 22:29:37
简单的Python人脸识别系统
2023-01-26 23:31:57
windows系统Tensorflow2.x简单安装记录(图文)
2023-02-22 04:41:23
![](https://img.aspxhome.com/file/2023/4/127804_0s.png)
PHP代码加密和扩展解密实战
2023-11-17 02:58:00
利用Python操作MongoDB数据库的详细指南
2024-01-16 13:49:28
![](https://img.aspxhome.com/file/2023/2/101082_0s.png)
Python列表原理与用法详解【创建、元素增加、删除、访问、计数、切片、遍历等】
2023-06-05 11:08:40
![](https://img.aspxhome.com/file/2023/9/133869_0s.png)
xorm根据数据库生成go model文件的操作
2024-01-16 00:29:22
python之用Numpy和matplotlib画一个魔方
2022-10-21 16:12:48
![](https://img.aspxhome.com/file/2023/0/125030_0s.jpg)
FrontPage 2000主页设计问与答
2008-08-02 12:37:00
asp程序运行速度测试
2008-02-11 19:11:00