python 使用requests 访问 繁体字网站会出现乱码,不知怎么解决?
巴扎黑
巴扎黑 2017-04-18 10:18:35
[Python讨论组]
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
巴扎黑
巴扎黑

全部回复(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'
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号