1
だから私はきちんとterminaltablesで.table
機能が、これまでの運をエンコードする方法を把握しようとしています。terminaltablesのasciitablesとエンコーディング
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import re
from terminaltables import AsciiTable
html = """<a href="#" class="link" title="Some title B">
Some text with åäö</a>"""
soup = BeautifulSoup(html, "html.parser")
test = soup.find('a').get_text(strip=True).encode('utf-8')
test_list = [test]
test_table = AsciiTable(test_list)
print test_list
print test
print test_table.table
これは
['Some text with \xc3\xa5\xc3\xa4\xc3\xb6']
Some text with åäö
そしてtest_table.table
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc3 in position 0: unexpected end of data