Reputation:
<div class="ContentFooter ReadingContentFooter AnswerFooter" id="__w2_wFc2PGId125_content_footer">
<span>1.6k views</span>
<span>2 views</span>
<span class="bullet"> · </span>
<a class="VoterListModalLink" href="#" id="__w2_wFc2PGId130_modal_link">View 5 Upvoters</a>
</div>
I want to xpath
<span>2 views</span>
which is greater than 1 view.
Upvotes: 0
Views: 691
Reputation: 5915
Assuming you have the following HTML :
<div class="ContentFooter ReadingContentFooter AnswerFooter" id="__w2_wFc2PGId125_content_footer">
<span>1.6k views</span>
<span>1 view</span>
<span>2 views</span>
<span class="bullet"> · </span>
<a class="VoterListModalLink" href="#" id="__w2_wFc2PGId130_modal_link">View 5 Upvoters</a>
</div>
The following XPath will select span
elements with content greater than 1 (view) (translate
and substring-before
are used to clean the content of the span
element before testing it):
//span[translate(substring-before(.,' '),'k','')>1]
Output :
<span>1.6k views</span>
<span>2 views</span>
EDIT : If you need to strenghten your XPath, you can go with :
//div[@id="__w2_wFc2PGId125_content_footer"]/span[starts-with(translate(.,"0123456789","¤¤¤¤¤¤¤¤¤"),"¤")][contains(.,'view')][translate(substring-before(.," view"),"k","")>1]
Upvotes: 0