Solution 1 :

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]

Problem :

<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.

Comments

Comment posted by D. Pardal

I don’t think that’s possible with XPath.

Comment posted by Moises Park

I thought you could do math operations in xpath

By

Leave a Reply

Your email address will not be published. Required fields are marked *