嗨,我正在运行一个程序来解析HTML地址中的表。它一切正常,我可以打印我提取的数据。但是,当我尝试写入数据的txt文件时,我收到下面的错误消息。任何人都可以帮助我吗?不知道我错过了什么。写入文本文件时出错Python
myfile.write(tds[0].text+ ","+ tds[4].text+ ","+ tds[7].text+ ","+ tds[12].text+ ","+ tds[14].text+ ","+ tds[17].text)
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "teste.py", line 14, in <module>
myfile.write(tds[0].text+ ","+ tds[4].text+ ","+ tds[7].text+ ","+ tds[12].text+ ","+ tds[14].text+ ","+ tds[17].text.encode('utf8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1: ordinal not in range(128)
当我使用STR(TDS [*])书写的作品,但它写入整个td标签不仅仅是信息。像这样:
对不起,我错过了你的部分问题。现在听起来像你在谈论你如何解析html或xml。你以前用过美丽的汤:http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html – sahutchi
是的,我使用的是美丽的。 – user3319895