爬蟲302重定向問題
阿新 • • 發佈:2018-12-30
可以通過判斷請求狀態分別進行不同的程式、
def down_load(url): headers1 = { ******************* } html = requests.get(url=url,headers=headers1,allow_redirects=False) print(html.status_code) # print(html.headers["location"]) if html.status_code == 302: new_id_url="http://www.***.com"+html.headers["location"] print(new_id_url) new_html=requests.get(url=new_id_url,headers=headers1).text return etree.HTML(new_html) else: print("++++++++++++++++") print(url) # print(requests.get(url=url,headers=headers1).text) return etree.HTML(requests.get(url=url,headers=headers1).text) down_load("**************")