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

查看:375
本文介绍了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'

这篇关于python 使用requests 访问 繁体字网站会出现乱码,不知怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆