使用 Python 从 Power BI 网站抓取数据表

问题描述 投票:0回答:0

我想从这个page中抓取表格数据。该页面在 Power BI 上运行。

我已经成功地使用以下代码获取了一些数据:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

main_url = "http://paineis.mdr.gov.br/?width=1280px&height=2569px&complementoEnderecoPowerBI=eyJrIjoiOWRlNjNkM2UtNzM1Zi00MDc4LWFlMWQtNWU0ODIwYzY2ZWMzIiwidCI6Ijk2MTFlY2UxLTM0MTQtNGMzNS1hM2YwLTdkMTAwNDI5MGNkNiJ9"

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)
driver.get(main_url)    
initial_table = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.innerContainer")))
table_text = initial_table.text

我能够得到的输出是前12行,如下图

输出

结果示例如下所示:

id_protocolo\ncd_protocolo\ndt_ocorrencia\n dt_protocolo\ndt_envio_processo\n
dt_homologacao_estadual\nUF\nMunicípio\nNM_DESASTRE\nQtd Protocolos\n
186367\nAC-F-1200054-12100-20230325\n25/03/2023 11:30:00\n27/03/2023 13:59:12\n
28/03/2023 18:56:42\n AC\nAssis Brasil\nInundações\n1\n

问题

向下滚动后,新行只会出现在页面源代码中。因此,除非我向下滚动,否则我的输出是有限的。这篇 post 为使用 R (RSelenium) 的类似问题提供了答案,但我无法复制他的解决方案。在这个 post 和另一个 post 中,针对类似问题有两种解决方案,但他们的表格没有向下滚动选项。

问题

有办法解决这种向下滚动的情况吗?

python selenium-webdriver powerbi rselenium
© www.soinside.com 2019 - 2024. All rights reserved.