Ian Bicking: the old part of his blog

Re: Xml processing comment 000

You can change BeautifulSoup structures. For example, you can insert raw html fragments:

>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup('<html><body><p> text 1 <p> text 2 </html>')
>>> print soup
<html><body><p> text 1 </p><p> text 2 </p></body></html>
>>> par2 = soup('p')[1]
>>> par2.name = 'div'
>>> par2.contents = ['<p>'] + par2.contents + ['</p>']
>>> print soup
<html><body><p> text 1 </p><div><p> text 2 </p></div></body></html>
Comment on Xml processing comment 000
by Alexander Kozlovsky