python - xpath: return value within an element found by preceeding value -
apologies weird title (hard explain). here html:
<p> <strong>date:</strong> may 12, 2015 </p>
basically, want extract date (may 12, 2015
). i've come with:
print advisory.xpath('//p/strong[text()="date:"]')[0].text
but naturally returns date:
. idea how traverse parent, skip w/e in strong tag , return rest?
alternatively, since date text after-text of <strong>
element, can use tail
attribute this:
[2]: s = '''<root><p><strong>date:</strong> may 12, 2015</p></root>''' in [3]: lxml import etree et in [4]: tree = et.fromstring(s) in [5]: tree.xpath('//p/strong[text()="date:"]')[0].tail out[5]: ' may 12, 2015'
Comments
Post a Comment