爬虫中文乱码解决方法

今天练习小爬虫爬取网页壁纸,发现获取到图片title属性是中文乱码,去网上找,发现方法有如下两种,特此记录,谨防下次忘记

方法1

(节点↓) (节点↓)
imgName = imgName.encode(‘iso-8859-1’).decode(‘gbk’)

方法2

response = requests.get(url)
response.encoding='utf-8’或者response.encoding=‘gbk’
方法2传送门

猜你喜欢

转载自blog.csdn.net/Vixcity/article/details/109309234