When using lxml I often want more information about an element. When using print (element)
one does not get much information. Is it possible to change this? It would be nice if I could write a custom function that displays more information, e.g. the element's text. I already tried setattr
, but this does not work. The reason for this is explained here.
An example:
from lxml import etree
root = etree.fromstring("<html>this is a test</html>")
print (root)
The is results in: <Element html at 0x7f582daeb700>
Update: Ideally, I would want to be able to just write print (element)
and get a nicely formatted output. I was hoping that I could achieve this using a custom __str__
method somehow.