Python 美素素素不能正确显示韩文字母

Python 美素素素不能正确显示韩文字母,python,beautifulsoup,Python,Beautifulsoup,我是Python的新手,正在使用BeautifulSoup学习解析 这是我的密码 #-*- coding: utf-8 -*- import urllib from bs4 import BeautifulSoup soup = BeautifulSoup(urllib.urlopen('https://news.google.com/news/section?cf=all&pz=1&q=IoT').read()) editData = soup.find_all('span

我是Python的新手,正在使用BeautifulSoup学习解析

这是我的密码

#-*- coding: utf-8 -*-

import urllib
from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib.urlopen('https://news.google.com/news/section?cf=all&pz=1&q=IoT').read())
editData = soup.find_all('span',{'class','titletext'})

print editData
结果如下: (韩文字母显示为“\uc720\ud50c\ub7ec\uc2a4”等)

[LG\uc720\ud50c\ub7ec\uc2a4,物联网\uc720\ub9dd\uae30\uc5c5\ubc1c\uad74\u2026\uc0c1\uc0dd\ud611\ub825\ucd94\uad6c,LG\uc720\ud50c\ub7ec\uc2a4\uc720\ub9dd物联网\uc911\uc18c\uae30\uc5c5\uc9c0\uc6d0,LGU+“物联网\uc720\ub9dd\UC9DD\uc911\uc18c\uc5ec\UC778”,“物联网\ub85c\uace0\uce35\ube4c\ub529\uc5d0\ub108\uc9c0\uc18c\ube44 80%\u2193"(2)UC2 2 D C\UD0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 uc0ac,'\uc0c1\uc0dd'\uc774\uacb0\uad6d\ubbf8\ub8\ubd81\ubbff8<代码>IoT\Ubbbf8<代码>IoT\UC2 4\Ub8\ubbf8\ubbf8<代码>IoT\uc2a4\Ub9\UB8\UB8\UB8\UB8\UB8\UB8\UB8\UB8\UB8\u8\u8\uB8\uB8\u8\uB8\uB8\uB8\uB8\uB8\u8\uB8\uB8\uB8\u8\uB8\u8\uBf8\u8\uBf8\uBf8\u8\uBf8\uBf8\uBf8\u8\ub8\u8\uBf8\u8\ub8\u8\uBf8\u8\ub8\u8\uBf8\ub8\u布8\u8\u布4\uce58\ucd9c\uc2dc\uace0\ub824\ub300,\uc815\ubcf4\ud1b5\uc2e0\uace0\ub3c4\ud654\ud55c'物联网\ucea0\ud37c\uc2a4'\ubcc0\uc2e0

……等等


我找不到有关此问题的任何解决方案。

这不是因为美观,而是因为打印节点的方式。执行以下操作:

print editData
将调用节点的函数
\uuu repr\uu()
,该函数通过将内容返回为ascii字符串来实现

试试这个:

for span in editData:
    print span.text

您应该看到unicode文本(for in循环是因为结果是一个节点列表,而不是单个节点,所以我们将它们全部打印出来).

您直接打印了HTML标记列表。容器内容始终使用称为表示的调试格式显示,对于字符串,这是一种ASCII安全的Python字符串文字格式,您可以复制并粘贴到新的Python脚本或交互式会话中,对于HTML标记,它将显示BeautifulSoup表示(看起来好像您将原始HTML标记写入了终端)。请尝试打印每个标记的文本内容:
对于editData中的标记:print tag.text()
。您在python 3中尝试过吗?