I am using Python to programmatically generate HTML. The HTML I want to generate is this:
<p>Hello <b>world</b> how are you?</p>
However, I do not know how to add the hello
before the <b>
tag and the string how are you?
after the bold tag.
My code looks like this:
from xml.etree import ElementTree
p = ElementTree.Element('p')
b = ElementTree.Element('b')
b.text = 'world'
p.append(b)
Where would I add hello
and how are you
? The paragraph element only has one p.text
field, and there does not seem to be a way to intersperse text and other HTML tags when building the document.
How can I programmatically generate an HTML document with both tags and text mixed together?