如何解决Python:Selenium无法读取特定表
我正在尝试读取this table中元素的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
有人知道这张桌子有什么花招吗?我用硒其他次没有问题。而且那个地方是公开的,所以我认为它没有任何障碍物。
先行感谢!
解决方法
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,".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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。