Python: selenium can't read an specific table

93 Views Asked by At

I am trying to read and take the href for the elements from this table, but I can't I try selenium and urllib library but neither work:

driver = webdriver.Chrome('C:/Users/Public/chromedriver')
driver.get(str(link))
driver.implicitly_wait(30)
time.sleep(10)
try:
    element = WebDriverWait(driver, 50).until(
        EC.presence_of_element_located((By.CLASS_NAME, "tabla_datos_linea"))
    )
    for a in driver.find_elements_by_partial_link_text('impacto'):
        print(a.text)
        
    
finally:
    driver.quit()

I exagerate in this code the conditions used to wait for the DOM to load with explicit and implicit wait, but still is not taking the table :(. The output of this code is:

Expediente de evaluación de impacto ambiental

but I want this:

Expediente de evaluación de impacto ambiental
Estudio de impacto ambiental Firmado con certificado digital acreditado

Does anyone knows if this table has some trick or something? I used selenium other times without problem. And that place is public so I don't think it has some blockers or something.

thanks before hand!

1

There are 1 best solutions below

0
On BEST ANSWER

The inner table present inside an iframe and you need switch to iframe first in order to access the elements.

driver.get("https://seia.sea.gob.cl/expediente/expedientesEvaluacion.php?modo=ficha&id_expediente=2148718463")
elements=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".tabla_datos_linea ul.yui-nav a")))
for element in elements[1:]:
    print(element.text)
    print(element.get_attribute("href"))

WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"miFrame")))
elementsinnertable=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".tabla_datos_linea a[href^='https://seia.sea.gob.cl/documentos/documento.php']")))
for a in elementsinnertable:
    print(a.text)
    print(a.get_attribute("href"))

Console Output:

Expediente de evaluación de impacto ambiental
https://seia.sea.gob.cl/expediente/expedientesEvaluacion.php?modo=ficha&id_expediente=2148718463#-1
Participación ciudadana
https://seia.sea.gob.cl/expediente/expedientesEvaluacion.php?modo=ficha&id_expediente=2148718463#-1
Carta de envío texto radiodifusión
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148718469
Extracto
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148718470
Estudio de impacto ambiental
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148718467
Resolución de Admisibilidad
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148822701
Notificación de documento
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148824474
Solicitud de evaluación de EIA
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148834061
Solicitud de evaluación de EIA a gobierno regional
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148834086
Solicitud de evaluación de EIA a municipalidad
https://seia.sea.gob.cl/documentos/documento.php?idDocumento=2148834093