14
我想制作搜索引擎,并在某些网页中关注教程。 我想测试解析HTMLPython 3 UnicodeDecodeError:'charmap'编解码器无法解码字节0x9d
from bs4 import BeautifulSoup
def parse_html(filename):
"""Extract the Author, Title and Text from a HTML file
which was produced by pdftotext with the option -htmlmeta."""
with open(filename) as infile:
html = BeautifulSoup(infile, "html.parser", from_encoding='utf-8')
d = {'text': html.pre.text}
if html.title is not None:
d['title'] = html.title.text
for meta in html.findAll('meta'):
try:
if meta['name'] in ('Author', 'Title'):
d[meta['name'].lower()] = meta['content']
except KeyError:
continue
return d
parse_html("C:\\pdf\\pydf\\data\\muellner2011.html")
,并得到错误
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 867: character maps to <undefined>enter code here
我看到了网络上的一些解决方案使用的编码()。但我不知道如何在代码中插入encode()函数。谁能帮我?
什么是异常的**完整**回溯? –