如何在python中显示汉字?

问题描述 投票:-1回答:1

PYTHON:尝试从中文网站捕获内容,但返回结果未显示中文字符。如何解决这个问题呢?

代码:

import urllib.request
doc="http://data.eastmoney.com/cjsj/weeklystockaccountsnew.aspx?p=1"
st = urllib.request.urlopen(doc)
ct = st.read()
print(ct)
st.close()
python character cjk
1个回答
0
投票

您读取的字节对象采用中文GB2312编码。使用之前,您必须将其解码为Unicode字符串:

ct = st.read().decode('gb2312')
© www.soinside.com 2019 - 2024. All rights reserved.