【发布时间】:2022-11-22 19:39:58
【问题描述】:
我现在已经成功地设置了一个脚本,从这个网站的表格中提取一些信息:https://www.nordpoolgroup.com/en/Market-data1/Power-system-data/Production1/Wind-Power-Prognosis/SE/Hourly/?view=table
现在,我想在 2021 年的所有日期都执行此操作。我想我必须使用 input id="data-end-date" 并激活某种按钮推送器,但我不明白这在理论上是如何完成的,而且还没有找到任何类似的问题。
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)#optional
webdriver_service = Service("./chromedriver") #Your chromedriver path
driver = webdriver.Chrome(service=webdriver_service,options=options)
data = []
driver.get('https://www.nordpoolgroup.com/en/Market-data1/Power-system-data/Production1/Wind-Power-Prognosis/SE/Hourly/?view=table')
time.sleep(3)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@class="pure-button"]'))).click()
time.sleep(1)
soup = BeautifulSoup(driver.page_source,"html.parser")
df1 = pd.read_html(str(soup))[1]
df1.drop(columns=['22-11-2022', 'SE'], inplace=True)
df1.drop(range(24,29), axis=0, inplace=True)
print(df1)
谢谢你。
【问题讨论】:
-
当您在这里询问 2021 年以来的历史数据时,该页面显示预测、未来数据。您确定可以在那里找到它吗?
-
是的,我敢肯定。例如,如果我查看表中的 2021-01-01 01:00,它会给出 2021-01-02 01:00 的预测值。
标签: python selenium web-scraping