xpath之starts-with()

一般写法

北塔ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

from lxml import  etree

html = '''
    
  • 需要的内容1
  • 需要的内容2
  • 需要的内容3
  • ''' selector = etree.HTML(html ) contents = selector.xpath ( '//li[@class = "tag_1"]/text()') print(contents)

    输出:
    D:\Python\venv\Scripts\python.exe D:/Python/venv/test9.py
    ['需要的内容1']

    Process finished with exit code 0

    starts-with()可以获取类似标签的信息。

    from lxml import  etree
    
    html = '''
        
  • 需要的内容1
  • 需要的内容2
  • 需要的内容3
  • ''' selector = etree.HTML(html ) contents = selector.xpath ( '//li[starts-with(@class ,"tag")]/text()') for content in contents: print (content)

    输出:
    D:\Python\venv\Scripts\python.exe D:/Python/venv/test9.py
    需要的内容1
    需要的内容2
    需要的内容3

    Process finished with exit code 0
    **


    网站栏目:xpath之starts-with()
    浏览地址:http://myzitong.com/article/jcihjh.html