利用lxml,得到html元素的绝对xpath路径

#coding=gbk
import lxml.etree
import lxml.html as x

f=open('f:/test.html','r')
c=f.read()
doc=x.document_fromstring(c)
alist=doc.xpath("//a")

for a in alist:
    tree=lxml.etree.ElementTree(a)
    print tree.getpath(a)

你可能感兴趣的:(html,C++,c,F#,C#)