0

When I try to get information it returns empty list. If I write different class such as 'tr-indent2' or something it returns value in a bad format which means it can take data but not for every class.

liste=[]

linkss=['https://ClinicalTrials.gov/show/NCT05768724','https://ClinicalTrials.gov/show/NCT05768607']
for data in linkss:
    path=r"C:\Users\kaant\Downloads\chromedriver.exe"
    service=Service(executable_path=path)
    options = uc.ChromeOptions() 
    options.headless = True 
    driver = uc.Chrome() 
    driver.get(data)  
    time.sleep(5) 
    infos=driver.find_elements(By.CLASS_NAME, value="ct-layout_table tr-tableStyle tr-moreInfo")
    c=[]
    
   
    for info in infos:
        c.append(info.text)
        
        
    liste.append(c)
        
        
    driver.quit()

How can I get this class? Thanks

2 Answers2

0

The class you are looking for is nested in several other div's, so you need to use By.XPATH:

infos=driver.find_elements(By.XPATH, '//div[@class="tr-indent1"]//div[@class="tr-indent2"]//table[@class="ct-layout_table tr-tableStyle tr-moreInfo"]')
user510170
  • 286
  • 2
  • 5
0

To extract the required information you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get("https://clinicaltrials.gov/ct2/show/NCT05768724")
    print([my_elem.text for my_elem in driver.find_elements(By.CSS_SELECTOR, "table.ct-layout_table.tr-tableStyle.tr-moreInfo")])
    
  • Using XPATH:

    driver.get("https://clinicaltrials.gov/ct2/show/NCT05768724")
    print([my_elem.text for my_elem in driver.find_elements(By.XPATH, "//table[@class='ct-layout_table tr-tableStyle tr-moreInfo']")])
    
  • Note : You have to add the following imports :

    from selenium.webdriver.common.by import By
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352