python 重定向获取真实url
时间:2019-06-13来源: 作者: 文章热度: ℃
点评:有时采集到网址是重定向的我们需要重新获取真实地址此时以下代码能帮上你
def get_real_url(url,try_count = 1):
if try_count > 3:
return url
try
def get_real_url(url,try_count = 1):
if try_count > 3:
return url
try
...时采集到网址是重定向的我们需要重新获取真实地址此时以下代码能帮上你
帝国cms认为此方法有时候还很实用的
def get_real_url(url,try_count = 1): if try_count > 3: return url try: rs = requests.get(url,headers=http_headers,timeout=10) if rs.status_code > 400: return get_real_url(url,try_count+1) return rs.url except: return get_real_url(url, try_count + 1) get_real_url("http://www.sfk8.com/") get_real_url("http://www.j0.7.com/") |
帝国cms认为此方法有时候还很实用的
相关python教程:
最新python教程: