我有這樣XML解析問題編碼錯誤
<?xml version="1.0" encoding="UTF-8"?>
<tw>
<tweet>
<yazi>atılacak tweet 1</yazi>
<resim>resim.png</resim>
</tweet>
<tweet>
<yazi>atılacak tweet 2</yazi>
<resim>yok</resim>
</tweet>
</tw>
一個XML文件,我想用
import xml.etree.ElementTree as ett
e = ett.parse("tweet.xml").getroot()
讀它,但我得到這個錯誤,
xml.etree.ElementTree.ParseError: encoding specified in XML declaration is incorrect: line 1, column 31
爲什麼?我如何解決這個問題,我搜索了很多,XML文件看起來不錯。我不明白爲什麼我不能讀取文件。
無法複製。我複製粘貼到一個文件並運行此代碼沒有問題。 – idjaw
@idjaw嗯,我得到這個錯誤,我在Windows上工作 – GLHF
我無法複製你的錯誤。我將你粘貼的XML文件複製到一個文件中。我複製了該代碼並運行它,它對我來說工作正常。我無法重現您的錯誤。 – idjaw