Python / ElementTree: writing to a file without namespaces

I am trying to write an ElementTree object to disk. Everything works, except that the output file looks like this:

<html:html lang="en-US" xml:lang="en-US" xmlns:html="http://www.w3.org/1999/xhtml">
<html:head>
<html:title>vocab</html:title>
<html:style type="text/css"> ...

Since he received the namespace information html:, the browser cannot display it.

How can I make etree save some html to disk without namespace information html:?

Here is the code I use to write:

with open('/path/to/file.html', mode='w', encoding='utf-8') as outfile:
mypage.write(outfile)

Thank!

+3
source share
1 answer

Well, it works for me, but with some kind of roundabout way.

( etree.tostrng()), re.sub('html:', '', thetext), . .

0

All Articles