How to get the text after the tag is found
Example:
#!/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
tag el with the text PointN found out how to get text TextN?
Since TextN follows the <b> that you already found, you can use the XPath following axis:
dom.xpath('//b[text() = "PointN:"]/following::node()')[0]
Another way is:
el = dom.xpath('//b[text()="PointN:"]')[0]
print el.tail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With