我正在从存储在csv中的URL列表中抓取信息。通过urllib.request.urlopen运行URL列表时得到HTTPError: HTTP Error 404: Not Found
,但是所有链接的status_code
均为200或302。有八个链接的状态为302。
我阅读了urllib文档,它看起来urllib.request应该能够处理重定向。
url_list = df_1.responseurl.tolist()
for url in url_list:
headers = {'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'}
req = Request(url, headers=headers)
html = urllib.request.urlopen(req).read()
f = open (i.strip('.csv'),'a+',encoding="utf-8")
f.write(text_from_html(html))
f.close()
我对urllib如何处理302链接有误解吗?