I\'m trying to print/save a certain element\'s HTML from a web-page.
I\'ve retrieved the requested element\'s XPath from firebug.
All I wish is to save this ele
Your XPath is obviously a bit too long, why don't you try shorter ones and see if they match. One problem might be "tbody" which gets automatically created in the DOM by browsers but the HTML markup usually does not contain it.
Here's an example of how to use XPath results:
>>> from lxml import etree
>>> from StringIO import StringIO
>>> doc = etree.parse(StringIO("<html><body>a<something/>b</body></root>"), etree.HTMLParser())
>>> doc.xpath("/html/body/text()")
['a', 'b']
So you could just "".join(...)
all text parts together if needed.
Not sure I completely follow what you are trying to accomplish, but ultimately I think you are looking for:
print etree.tostring(elem[0])