Python:selenium can';不要看具体的表格

Python:selenium can';不要看具体的表格,python,selenium,web-scraping,css-selectors,webdriverwait,Python,Selenium,Web Scraping,Css Selectors,Webdriverwait,我正在尝试从中读取并获取元素的href,但我无法尝试selenium和urllib库,但两者都不起作用: 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_

我正在尝试从中读取并获取元素的href,但我无法尝试selenium和urllib库,但两者都不起作用:

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()
在这段代码中,我用显式和隐式等待测试了用于等待DOM加载的条件,但仍然没有使用表:(。 此代码的输出为:

Expediente de evaluación de impacto ambiental
但我想要这个:

Expediente de evaluación de impacto ambiental
Estudio de impacto ambiental Firmado con certificado digital acreditado
有人知道这张桌子有什么把戏吗?我以前也用过selenium,没什么问题。那个地方是公共场所,所以我不认为它有什么拦截器之类的东西


谢谢!内部表格位于
iframe
中,您需要先切换到
iframe
才能访问元素

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"))
控制台输出:

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

你确定你没有把它放在最上面吗?(xpath到它->
/html/body/div/div[2]/table/tbody/tr/td/div[1]/ul/li[2]/a/em
)…我建议使用for循环,它将使用xpath遍历该表…但在我看来…您永远不会获得DOM加载的数据…我建议您尝试使用一些JS脚本(我没有看到selenium正在检查JS相关的东西…据我所知,它只是将HTML内容作为局部变量抓取并通过它进行验证…但我可能错了)祝你好运…我会得到XPath:)