Tôi muốn làm cho công cụ tìm kiếm và tôi làm theo hướng dẫn trong một số trang web. Tôi muốn thử nghiệm phân tích cú pháp htmlPython 3 UnicodeDecodeError: 'charmap' giải mã không thể giải mã byte 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")
và nó nhận được lỗi
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 867: character maps to <undefined>enter code here
tôi thấy một số giải pháp trên Web bằng cách sử dụng mã hóa(). Nhưng tôi không biết làm thế nào để chèn mã hóa() chức năng trong mã. Ai giúp tôi với?
** toàn bộ truy xuất ngoại lệ ** là gì? –