xpath

1

selector.xpah("//*[@id='df']")

// 后面的*  所有的元素

2

call_form = selector.xpath("//*[@id='details_table']/tbody/tr")

选取这个tbody下的所有的tr

3

selector.xpah("//*[@id='df']/@value")

选取下面的value

4  输出一个节点下的   文字

kk = selector.xpath('//tr[@class="content2"]')
print kk
for i in kk:
print(i.xpath('string(.)'))

5 将一个节点下的内容转化成文字
kk = selector.xpath('//tr[@class="content2"]')
print kk[2]
ll = etree.tostring(kk[2],encoding='utf8')
print ll
原文地址:https://www.cnblogs.com/jiangyuanzhi/p/6882792.html