1. 程式人生 > >python在gbk編碼轉換成utf-8時亂碼問題

python在gbk編碼轉換成utf-8時亂碼問題

#專案爬蟲,環境python-下載匯入requests、lxml包
#url時是查ip位置的介面
url_1='http://www.ip138.com/ips138.asp?ip='+str(kh_ip)+'&action=2'
#匯入requests庫.獲取整個頁面文件
html_1=requests.get(url_1).text
#先encode('iso-8859-1')轉換成'iso-8859-1編碼,後轉GBK就ok了
print(html_1.encode('iso-8859-1').decode('gbk'))

網友們遇事一定要冷靜哦,要不然越搞越亂,轉載請攜帶連結哦。