嗨,我正在運行一個程序來解析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