您的位置:首页技术文章
文章详情页

python 使用requests 访问 繁体字网站会出现乱码,不知怎么解决?

【字号: 日期:2022-09-23 16:31:41浏览:62作者:猪猪

问题描述

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:

根据该网页的代码:

<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’

标签: Python 编程
相关文章: