xpath取末尾

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[last()]/@class") #获取选中的div的最后一个

print(content1)

 

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