1
所以我想弄清楚如何在terminaltables中正确编码.table
函数,但到目前为止没有运气。terminaltables asciitables and encoding
# -*- 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