Lxml Change Unicode Characters

I use lxml to read the xml file and change a few details. However, at startup, I found that even if I just use lxml to read the file, then write it again, as shown below:

fil='iTunes Music Library.XML'
tre=etree.parse(fil)
tre.write('temp.xml')

I find Queensrÿche converted to Queensrÿche. Does anyone know how to fix this?

+3
source share
1 answer

Change your last line to:

tre.write('temp.xml', encoding='utf-8')

Otherwise, it lxmlwrites the XML to ASCII encoding, so it needs to avoid all non-ASCII characters.

+7
source

Source: https://habr.com/ru/post/1724767/


All Articles