Home > OS >  How to extract text if selenium returns empty tags?
How to extract text if selenium returns empty tags?

Time:01-29

I'm trying to scrape this Covid-19 Dashboard:https://rtc-planning.maps.arcgis.com/apps/dashboards/3b3a01c1d8444932ba075fb44b119b63, but it returns empty tags(< text></ text>) instead of (< text>Some Data</ text>) Here is my Code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent

options = Options()
options.headless = True

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

driver.get("https://rtc-planning.maps.arcgis.com/apps/dashboards/3b3a01c1d8444932ba075fb44b119b63")
wait = WebDriverWait(driver, 50)
element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "dock-element")))
search = driver.find_elements(By.TAG_NAME, "text")
count = 0
for i in search:
    count  = 1
    if count == 3:
         print(i.get_attribute('outerHTML'))

CodePudding user response:

    search = wait.until(EC.visibility_of_all_elements_located((By.TAG_NAME, "text")))
    count = 0
    for i in search:
        count  = 1
        if count == 3:
             print(i.get_attribute('outerHTML'))

The issue is you need to wait for the values to come up not just the presence of the element.

Not sure if you want to just use search[2] instead?

aka search[2].get_attribute('outerHTML')

<text vector-effect="non-scaling-stroke" font-size="160px">
        5,293
      </text>
  •  Tags:  
  • Related