Can't find table selenium python
Solution 1:
Selecting Balanço Patrimonial Ativo and then to extract the data from the DFs Consolidadas / Balanço Patrimonial Ativo - (Reais Mil) table from the website you need to induce WebDriverWait for the visibility_of_element_located() and using DataFrame from Pandas you can use the following Locator Strategy:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
driver.get("https://www.rad.cvm.gov.br/ENETCONSULTA/frmGerenciaPaginaFRE.aspx?NumeroSequencialDocumento=102142&CodigoTipoInstituicao=2")
Select(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "select#cmbQuadro")))).select_by_visible_text("Balanço Patrimonial Ativo")
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#iFrameFormulariosFilho")))
data = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "table#ctl00_cphPopUp_tbDados"))).get_attribute("outerHTML")
df = pd.read_html(data)
print(df)
Console Output:
[ 0 1 2 3
0 Conta Descrição 31/12/2020 31/12/2019
1 1 Ativo Total 987.419.000 926.011.000
2 1.01 Ativo Circulante 142.323.000 112.101.000
3 1.01.01 Caixa e Equivalentes de Caixa 60.856.000 29.714.000
4 1.01.02 Aplicações Financeiras 3.424.000 3.580.000
.. ... ... ... ...
61 1.02.03.03 Imobilizado em Andamento NaN NaN
62 1.02.04 Intangível 77.678.000 78.489.000
63 1.02.04.01 Intangíveis NaN NaN
64 1.02.04.01.01 Contrato de Concessão NaN NaN
65 1.02.04.02 Goodwill NaN NaN
[66 rows x 4 columns]]