Search code examples
pythonselenium-chromedriver

scrap 2 text values from html using python selenium chromedriver


I have webdriver which filters most of the required fields which I need from a webpage, but I am stuck in this part. I have to get 61 and 70% from the below. Can someone please help. I have tried driver.find_element_by_xpath("//p[@class="stock-score tykr-score-box"], but am lost in the text after that, how do i handle that followed by span class for 1st value, then followed by another span class for 2nd value.

Thanks a lot,
Sudip

<p class="data-score customer-score-box">This customer has a score of <span class="value-changes">61</span> <span class="light-value value-changes" style="margin-right: 5px; margin-left: 0px;">/100</span> and safety of <span class="value-changes" style="margin-right: 5px;">70% </span>therefore the case may <p class="greenColor" style="font-weight: 600;"> not </p> be <p class="greenColor" style="font-weight: 600;"> suitable</p></p>

Solution

  • You can get them passing the index of span element

    For 61 you can use below xpath

    //p[@class="data-score customer-score-box"]//span[1]
    

    For 70% you can use below xpath

    //p[@class="data-score customer-score-box"]//span[3]