xpath取其中几个使用position

家住魔仙堡 提交于 2020-03-11 13:58:42
from lxml import etree

html = '''
<!DOCTYPE html>
<html lang="en">
<head>
    <!--网页头部信息-->
    <title>网页名</title>
</head>
<body>
    <!--下面是网页正文-->
    <div class="two">id-text</div>
    <div class="one two">class-text</div>
    <div class="one">class-span</div>
    <div class="three">three</div>
</body>
</html>
'''

html =etree.HTML(html)

content1 = html.xpath("//div[position()>2 and contains(@class,'three')]/@class") #取div位置大于2的 并且类包含three的

print(content1)

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!