Using an XML etree, it's possible to do:
etree.getpath(element
How would I do the same thing, but with HTML instead of XML?
The _ElementTree
has a getpath
method:
In [17]: import lxml.html as LH
In [18]: content = '<root><div id="pgbrk" ......>....Page Break....</div></root>'
In [19]: root = LH.fromstring(content)
In [20]: tree = root.getroottree()
In [21]: tree.getpath(root[0])
Out[21]: '/html/body/root/div'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.