0

The code below returns the "H" value for the span variable but I am looking for it to return the dollar amount 23988.00. Edited HTML for more scope

search_highprice=[]
result_elements = driver.find_elements_by_xpath('//span[@class="tile_high-label"]')

for element in result_elements:
search_result = element.text
search_highprice.append(search_result)

<div class="tile_high-low pull-left" style="color: rgba(255, 255, 255, 0.67);">
  <div>
      <span class="tile_high-label">H</span> 
        23988.00
  </div>
   <div>
      <span class="tile_low-label">L</span> 
      23535.00
   </div>
</div>

1
  • It looks like the value you want is not inside the <span> tag. Commented Apr 27, 2020 at 17:51

1 Answer 1

1

The dollar amount is contained within the div.so you have to target the element.

search_highprice=[]
result_elements = driver.find_elements_by_xpath('//span[@class="tile_high-label"]/..')

for element in result_elements:
            search_result = element.text
            search_highprice.append(search_result)

you may need to trim the extra spaces from text before appending.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow. Your answer is spot on! Thank you I could not find that anywhere. Thank you I add a replace so my final answer is
search_result = element.text.replace('H','')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.