python解決中文亂碼的方法


1、手動將response設置為utf-8編碼

response=requests.get(url)
response.encoding='utf-8'
page_text=response.text

 

 

2、將字符串先進行iso-8859-1編碼,再進行gbk解碼

str=str.encode('iso-8859-1').decode('gbk')

 

3、

str=str.encode("gbk", 'ignore').decode("gbk", "ignore")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM