【发布时间】:2018-06-13 06:40:09
【问题描述】:
我正在尝试从网站上的表格中抓取数据。
page_soup = soup(html, 'html.parser')
stat_table = page_soup.find_all('table')
stat_table = stat_table[0]
with open ('stats.txt','w') as q:
for row in stat_table.find_all('tr'):
for cell in row.find_all('td'):
q.write(cell.text)
但是,当我尝试写入文件时,我收到以下错误消息:'ascii' codec can't encode character '\xa0' in position 19: ordinal not in range(128)。
我知道应该用.encode('utf-8')编码,但是
cell.text.encode('utf-8')
不起作用。
任何帮助将不胜感激。使用 Python 3.6
【问题讨论】:
标签: python encoding ascii file-writing