Reputation: 2481
How do i get the text of a child element, if the parent element contains text with a specific string?
For example:
<li>
"string1"
<span>
"Hello"
</span>
</li>
<li>
"string2"
<span>
"Ola"
</span>
</li>
From the above html code, how to get only string "Ola" using xpath?
Upvotes: 0
Views: 412
Reputation: 1813
Without knowing scrapy, I would try
//li[text()[contains(.,"string2")]]/span/text()
//li[text()[contains(.,"string2")]]
select a li
element that text contains string2
/span
select a element span
below the selected li
/text()
: return the text of the selected span elementUpdate: This is simpler and should also work:
//li[contains(text(),"string2")]/span/text()
Upvotes: 1