xpath取其中几个使用position

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)

 

posted @ 2020-03-11 13:31  brady-wang  阅读(2490)  评论(0编辑  收藏  举报