玩蛇网提供最新Python编程技术信息以及Python资源下载!

Python乱码问题又来了,访问繁体字网站出乱码怎么破?requests访问

In [12]: r = requests.get('http://www.hkex.com.hk/chi/stat/smstat/dayquot/d170202c.htm')

In [13]: r.text[-100:]
Out[13]: '´Á®§$2.60\r\n  717 \xad^¬ÓÃÒ¨é         ¥½´Á®§$0.0128\r\n\r\n2. «ü¼Æ\xad×\xadq\r\n\

r\n-\r\n\r\n</font></pre></body></html>\r\n

根据该网页的代码:

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

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd14069.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月14日 - 11时00分21秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules