1.请求时出现HTTP Error 403: Forbidden

headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}  

req = urllib.request.Request(url=url, headers=headers)  

urllib.request.urlopen(req).read()  

详细:https://www.2cto.com/kf/201309/242273.html

 

2.保存html内容时出现Python UnicodeEncodeError: 'gbk' codec can't encode character

f = open("out.html","w")  

换成

f = open("out.html","w",encoding='utf-8')  

详细:http://www.jb51.net/article/64816.htm

 

相关文章:

  • 2022-01-03
  • 2021-12-08
  • 2019-03-01
  • 2021-12-15
  • 2021-11-02
  • 2021-12-15
  • 2019-12-25
猜你喜欢
  • 2021-08-28
  • 2022-01-22
  • 2021-11-18
  • 2022-02-07
  • 2021-12-06
  • 2021-12-15
相关资源
相似解决方案