新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
xpath之starts-with()
一般寫法
北塔ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
from lxml import etree
html = '''
需要的內(nèi)容1
需要的內(nèi)容2
需要的內(nèi)容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
['需要的內(nèi)容1']
Process finished with exit code 0
starts-with()可以獲取類似標(biāo)簽的信息。
from lxml import etree
html = '''
需要的內(nèi)容1
需要的內(nèi)容2
需要的內(nèi)容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
需要的內(nèi)容1
需要的內(nèi)容2
需要的內(nèi)容3
Process finished with exit code 0
**
文章標(biāo)題:xpath之starts-with()
文章起源:http://fisionsoft.com.cn/article/jcihjh.html