Python中的请求解码

1 投票
1 回答
1269 浏览
提问于 2025-04-18 14:33
import urllib.request
url = ""
http_header = {
        "User-Agent": "Mozilla/5.0(compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0) like Gecko",
        "Accept": "text/html, application/xhtml+xml, */*",
        "Accept-Language": "ko-KR",
        "Content-type": "application/x-www-form-urlencoded",
        "Host": ""
}
params = {
        'id': 'asdgasd',
        'call_flag': 'idPoolChk',
        'reg_type': 'NY'
}

data = urllib.parse.urlencode(params).encode()
req = urllib.request.Request(url, data)
response = urllib.request.urlopen(req)
the_page = response.read()
print(the_page)

当我运行这个程序时,我得到了:

\xec\x95\x84\xec\x9d\xb4\xeb\x94\x94\xea\xb0\x80 \xec\xa4\x91\xeb\xb3\xb5\xeb\x90\xa9\xeb\x8b\x88\xeb\x8b\xa4

我该如何把这个转换成韩语呢?

1 个回答

1

这是UTF-8编码。

print(the_page.decode('utf-8'))

假设你的控制台能够处理这些字符。

撰写回答