如何从动态网页中提取信息

时间:2021-05-01 11:08:48

标签: selenium scrapy

点击查看详细信息的绿色按钮后,我会看到显示更多信息的弹出窗口。我如何抓取弹出窗口中的信息。 单击使用 selenium 后,我尝试提取信息,但我收到此错误

1 个答案:

答案 0 :(得分:1)

您在那里有一个 iframe,它会导致问题: 您可以像这样从弹出窗口中获取数据:

from selenium import webdriver
import time 

driver = webdriver.Chrome(executable_path="D:/chromedriver.exe")

driver.get('http://www.directoriomedicomexicano.com/Esp_Medicas/MedicosListado.aspx?P1=37&P2=ORTOPEDIA%20Y%20TRAUMATOLOGIA') 

#get all 'Ver detalles'
view_more_buttons = driver.find_elements_by_xpath("//img[contains(@onclick,'ShowWindow')]")

#click on the first one
view_more_buttons[0].click()

#switch to the iframe
iframe = driver.find_element_by_id("ctl00_ContentPlaceHolder1_ASPxPopupControl1_CIF1")
driver.switch_to.frame(iframe)

#wait 3 seconds
time.sleep(3)

#get the text from the table
table = driver.find_element_by_xpath("//table[@align='center']")

print(table.text)

enter image description here

相关问题