views:

49

answers:

2

I'm using the following code to locate a div:

parser = etree.HTMLParser()
tree = etree.parse(StringIO(page), parser)

div = tree.xpath("//div[@class='content']")[0]

My only problem is, that after doing this I do not want to rely on lxml to extract the contents of said div: I just want to get back the raw XML the div contains. Is this doable or do I have to abandon this method entirely?

+2  A: 

I think you are looking for:

etree.tostring(div)
unutbu
You're right: thank you!
akosch
A: 

Did you try tostring?

raw_xml = etree.tostring(div)
Ryan Ginstrom