Я пытаюсь автоматизировать загрузку файлов Excel с веб-сайта с помощью Python и Selenium. Я пробовал XPath, но думаю, что он сложнее моего кода. Как селекторы в кнопках. Любые предложения будут полезны.
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
from selenium.webdriver.common.keys import Keys
import time
xpath_ship_movements="//*[@id='Traffic']"
# xpath_ship_movements="xpath_full='/html/body/form/div/div[2]/div[1]/div[2]/ul/li[2]/a'"
xpath_days='//*[@id="rptGrid"]/div/div[2]/div[1]/div[2]/a[1]'
xpath_tools='//*[@id="rptGrid"]/div/div[2]/div[1]/div[2]/a[3]'
xpath_export='//*[@id="MSQ-WEB-0001"]'
url="https://qships.tmr.qld.gov.au/webx/#"
driver = webdriver.Edge()
# Open the webpage
driver.get(url)
driver.maximize_window()
wait = WebDriverWait(driver, 20)
# Wait for and click the "Ship Movements" button
ship_movements_button = wait.until(EC.element_to_be_clickable((By.XPATH, xpath_ship_movements)))
ship_movements_button.click()
# Wait for and click the "Next 7 days" button
next_7_days_button = wait.until(EC.element_to_be_clickable((By.XPATH, xpath_days)))
next_7_days_button.click()
# Wait for and click the Tools button
tools_button = wait.until(EC.element_to_be_clickable((By.XPATH, xpath_tools)))
tools_button.click()
# Wait for and click the Export to Excel option
export_to_excel = wait.until(EC.element_to_be_clickable((By.XPATH, xpath_export)))
export_to_excel.click()
# Wait for the export to complete
time.sleep(10)
# Close the browser
driver.quit()
Подробнее здесь: https://stackoverflow.com/questions/788 ... om-webpage