python urllib.request.urlretrieve 403报错解决

opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36')]
urllib.request.install_opener(opener)
urllib.request.urlretrieve(img_url, filepath)

 http://www.shanhubei.com/archives/2484.html

posted @ 2022-11-25 15:48  珊瑚贝博客  阅读(149)  评论(0编辑  收藏  举报