如何在找到标记后获取文本
例:
#!/usr/bin/env python
import lxml.html
html = """
<b>Point1:</b> Text1 <br>
<b>Point2:</b> Text2 <br>
...
<b>PointN:</b> TextN
<b>PointN+1:</b> TextN+1<br>
"""
dom = lxml.html.document_fromstring(html)
el = dom.xpath('//b[text()="PointN:"]')
print el
标签el与文本PointN发现如何获取文本TextN?
解决方法:
由于TextN遵循< b>你已经找到了,你可以使用XPath跟随轴:
dom.xpath('//b[text() = "PointN:"]/following::node()')[0]