文章詳情頁
python 使用requests 訪問 繁體字網(wǎng)站會出現(xiàn)亂碼,不知怎么解決?
瀏覽:76日期:2022-09-23 16:31:41
問題描述
In [12]: r = requests.get(’http://www.hkex.com.hk/chi/stat/smstat/dayquot/d170202c.htm’)In [13]: r.text[-100:]Out[13]: ’′á?§$2.60rn 717 xad^?ó?ò¨é ¥?′á?§$0.0128rnrn2. ?ü??xad×xadqrnrn-rnrn</font></pre></body></html>rn
問題解答
回答1:根據(jù)該網(wǎng)頁的代碼:
<html><head><meta name=’MS.LOCALE’ content=’ZH-TW’><title>Hong Kong Exchanges and Clearing Limited</title><meta http-equiv=’Content-Type’ content=’text/html; charset=big5’>
需指定字符編碼為 big5:
r = requests.get(’http://www.hkex.com.hk/chi/stat/smstat/dayquot/d170202c.htm’)r.encoding = ’big5’
上一條:html5 - python 處理html頁面爬蟲數(shù)據(jù)下一條:python - 關(guān)于爬取網(wǎng)站,下載圖片的時候碰到網(wǎng)址結(jié)構(gòu)問題卡住
相關(guān)文章:
排行榜

熱門標簽