I am trying to scrape data from
CodePudding user response:
To solve this problem, you can try using the ActionChains class in the selenium.webdriver.common.action_chains module to perform the mouse clicks and keyboard input necessary to select the options and click the button.
Here's some sample code that should do what you want:
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
# Select the "24 hours" option from the "averaging" dropdown
averaging_dropdown = driver.find_element(By.XPATH, '//*[@id="averaging"]')
averaging_option = driver.find_element(By.XPATH, '//*[@id="averaging"]/option[2]')
ActionChains(driver).move_to_element(averaging_dropdown).click(averaging_option).perform()
# Select the "maximum" option from the "Period" dropdown
period_dropdown = driver.find_element(By.XPATH, '//*[@id="period"]')
period_option = driver.find_element(By.XPATH, '//*[@id="period"]/option[3]')
ActionChains(driver).move_to_element(period_dropdown).click(period_option).perform()
# Click the "export" button
export_button = driver.find_element(By.XPATH, '//*[@id="toolbar"]/button[1]')
ActionChains(driver).move_to_element(export_button).click().perform()
# Wait for the download to complete
driver.implicitly_wait(30)
This code uses the ActionChains class to perform a series of actions in sequence:
Move the mouse cursor to the "averaging" dropdown element and click it to open the dropdown menu.
Move the mouse cursor to the "24 hours" option and click it to select it.
Repeat steps 1 and 2 for the "Period" dropdown and the "maximum" option.
Move the mouse cursor to the "export" button and click it to initiate the download.
Note that you may need to modify the XPath expressions to match the actual element paths on the website. You can use the developer tools in your web browser to inspect the elements and find their XPaths. I hope it will be of help to you