the*_*eta 7 python unicode beautifulsoup
所以我将一个带有.findAll(BeautifulSoup)的html页面解析为名为的变量result.如果我键入resultPython shell然后按Enter键,我会看到正常的文本,但是因为我想将此结果作为字符串对象进行后处理,我注意到str(result)返回垃圾,就像这个示例:
\xd1\x87\xd0\xb8\xd0\xbb\xd0\xbd\xd0\xb8\xd1\x86\xd0\xb0</a><br />\n<hr />\n</div>
Run Code Online (Sandbox Code Playgroud)
Html页面源是utf-8编码的
我怎么处理这个?
代码基本上就是这个,如果重要的话:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(urllib.open(url).read())
result = soup.findAll(something)
Run Code Online (Sandbox Code Playgroud)
Python是2.7
Joh*_*own 10
Python 2.6.7 BeautifulSoup.版本 3.2.0
这对我有用:
unicode.join(u'\n',map(unicode,result))
Run Code Online (Sandbox Code Playgroud)
我很确定a result是一个BeautifulSoup.ResultSet对象,它似乎是标准python列表的扩展
| 归档时间: |
|
| 查看次数: |
17430 次 |
| 最近记录: |