我試圖解析HTML page是我救了我的電腦(Windows 10)BeautifulSoup UnicodeEncodeError
from bs4 import BeautifulSoup
with open("res/JLPT N5 vocab list.html", "r", encoding="utf8") as f:
soup = BeautifulSoup(f, "html.parser")
tables = soup.find_all("table")
sectable= tables[1]
for tr in sectable.contents[1:]:
if tr.name == "tr":
try:
print(tr.td.a.get_text())
except(AttributeError):
continue
應該打印所有的日語單詞的第一列,但在print(tr.td.a.get_text())
有人提出錯誤說UnicodeEncodeError: 'charmap" codec can't encode character in position 0-1: character maps to (undefined)
那麼,如何我能解決這個錯誤嗎?