【发布时间】:2023-04-01 14:35:02
【问题描述】:
我试图从这个网站上抓取数据:https://www.rad.cvm.gov.br/ENETCONSULTA/frmGerenciaPaginaFRE.aspx?NumeroSequencialDocumento=102142&CodigoTipoInstituicao=2,但是从右上角的“Demonstração do Resultado”切换到“Balanço Patrimonial Ativo”,整个表格都在 CSS 选择器“#ctl00_cphPopUp_tbDados”下,但我无法使用 selenium webdriver 获取数据,我认为该表是动态的并在脚本下加载,但我不知道获取此数据的其他方法。到目前为止的完整代码如下:
cvm = input('Códigos CVM separados por vírgula: ')
lstcvm = list(map(str,cvm.split(',')))
for i in lstcvm:
url="https://bvmf.bmfbovespa.com.br/cias-listadas/empresas-listadas/ResumoDemonstrativosFinanceiros.aspx?codigoCvm="+i+"&idioma=pt-br"
driver = webdriver.Firefox()
driver.get(url)
dfp = driver.find_element(By.CSS_SELECTOR, "#ctl00_contentPlaceHolderConteudo_rptDocumentosDFP_ctl00_lnkDocumento")
webdriver.ActionChains(driver).click(dfp).perform()
time.sleep(10)
tabs=driver.window_handles
driver.switch_to.window(tabs[1])
print(driver.current_url)
box = driver.find_element(By.CSS_SELECTOR, "#cmbQuadro")
box.send_keys(Keys.HOME, Keys.RETURN)
time.sleep(1)
driver.maximize_window()
time.sleep(1)
balanco=driver.find_element(By.CSS_SELECTOR, "#ctl00_cphPopUp_tbDados").text
balanco
driver.switch_to.window(tabs[0])
print(driver.current_url)
print("Finalizado")
这里的样本输入是9512
用于抓取数据的部分代码如下:
balanco=driver.find_element(By.CSS_SELECTOR, "#ctl00_cphPopUp_tbDados").text
【问题讨论】:
标签:
python
pandas
dataframe
selenium
web-scraping
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:找不到表硒python - Python技术站