0

It is a dynamic span. I want to get the number that keeps changing. In this case it would be 436

Code trials:

valorliquido = navegador.find_element_by_css_selector("span[class="woocommerce-summary__item-value"]")

Got:

valorliquido = navegador.find_element_by_css_selector("span[class="woocommerce-summary__item-value"]")
                                                                   ^
SyntaxError: invalid syntax

Snapshot of the HTML:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

You have used double-quotes to wrap the class name of the CSS selector and also to wrap the whole selector string. This causes a syntax error because the interpreter is not able to distinguish between the two sets of double-quotes.

You can fix this by using single quotes

valorliquido = navegador.find_element_by_css_selector('span[class="woocommerce-summary__item-value"]')

Or escaping the double quotes so they have no effect

valorliquido = navegador.find_element_by_css_selector("span[class=\"woocommerce-summary__item-value\"]")
N. Hamelink
  • 603
  • 5
  • 14
0

You have to take care of a couple of things:


Solution

Youe effective line of code will be:

valorliquido = navegador.find_element(By.CSS_SELECTOR, "span.woocommerce-summary__item-value span[data-wp-component='Text']")

To print the text 436:

print(navegador.find_element(By.CSS_SELECTOR, "span.woocommerce-summary__item-value span[data-wp-component='Text']").text)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352