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

 mobiledu2502871817 发布于 2022-10-27 01:31
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
\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'
    2022-11-12 01:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有