使用模块requests
方式代码如下:
import requests
url_string="http://******"
r = requests.head(url_string, stream=True)
print r.headers['Location']
设置属性:allow_redirects = True ,则head方式会自动解析重定向链接,requests.get()方法的allow_redirects默认为True,head方法默认为False
url_string="http://******"
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"]
短URL系统、301/302重定向
短 URL 系统是怎么设计的?https://yq.aliyun.com/articles/87600 短网址(short URL)系统的原理及其实现 https://hufangyun.com/20 ...