Could not extract text from python selenium -


i have written following code extract price detail url.

from selenium import webdriver selenium.webdriver.common.desired_capabilities import desiredcapabilities  dcap = dict(desiredcapabilities.phantomjs) dcap["phantomjs.page.settings.useragent"] = ('mozilla/5.0 (windows nt 6.3; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/53.0.2785.89 safari/537.36') driver = webdriver.phantomjs(desired_capabilities=dcap) driver.get("https://www.walmart.com/ip/fitness-reality-tr3000-maximum-weight-capacity-manual-treadmill-with-pacer-control-and-heart-rate-system/37455841#") driver.find_element_by_css_selector("div[itemprop='price']:nth-of-type(1)").text 

it giving empty value although have price details inside particular tag.

when tried extracting innerhtmlof tag instead of text using following.

driver.find_element_by_css_selector("div[itemprop='price']:nth-of-type(1)").get_attribute("innerhtml") 

i these results

u' <span class="price-sup">$</span>199<span class="price-mark">.</span><span class="price-sup">00</span> ' 

it shows have text 199 inside tag couldnt extract it. missing here?

to price need following code:

price = driver.find_element_by_xpath('//div[@itemprop="price"]').text # due hidden element <span class="price-mark">.</>  # need specify floating point # or $19900 result not expect  price = '.'.join([price[:-2], price[-2:]]) 

result: $199.00


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -