Reputation: 9429
Given the following HTML string, parsed by lxml:
<strong class="footer">
<span class="icon-new"><i class="icon-new"/></span>
16
</strong>
How can I extract the number 16 with XPath?
Upvotes: 0
Views: 84
Reputation: 7173
with pure Xpath
//strong[@class='footer']/normalize-space(text()[position()=last()])
Upvotes: 1
Reputation: 11396
as '16' text is under the strong
tag, you may do it like:
>>> root = etree.fromstring(html)
>>> root.xpath('//strong[@class="footer"]/text()[normalize-space()]')[0].strip()
'16'
Upvotes: 2