[title]解决方案[/title]
headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36', 'Cookie': '' } url = 'http://www.weather.com.cn/textFC/hb.shtml' res = requests.get(url, headers = headers) # 下面的 res.text 改为 res.content 即可 soup = BeautifulSoup(res.text, 'html.parser')
改为 res.content 即可
soup = BeautifulSoup(res.content, ‘html.parser’)
参考文献:https://www.zhihu.com/question/19696249