Files
2026-01-30 11:28:35 +08:00

78 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
import time
from urllib.parse import urljoin
import pandas as pd
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from datetime import datetime
from selenium.webdriver.chrome.options import Options
from datetime import datetime, timedelta
from selenium.common.exceptions import NoSuchElementException
from tqdm import tqdm
from selenium.common.exceptions import TimeoutException
# 设置Chrome选项
chrome_options = Options()
# 设置为无头模式(不打开浏览器窗口)
# chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
# 指定ChromeDriver路径
service = Service(executable_path='D:\ProgramTools\chromedriver-win64\chromedriver.exe')
# 创建WebDriver对象
driver = webdriver.Chrome(service=service, options=chrome_options)
# 目标网址
url = 'https://ebc.cloud.harsonserver.com/#/user/login?redirect=/'
url1 = ''
username = '193WSX'
password = '193WSX'
# title = 'HGYH -- HGYH'
# 访问网页
driver.get(url)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, f'//*[@id="login-container"]/div[4]/div[3]/div'))).click()
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "form_item_loginAccount"))
).send_keys(username)
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "form_item_password"))
).send_keys(password)
time.sleep(2)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, f'//*[@id="login-container"]/div[4]/div[2]/form/div[5]/div/div/div/button'))).click()
time.sleep(3)
new_url = "https://ebc.cloud.harsonserver.com/#/maintenance/frontManage/maintenanceReport/workOrderReport"
driver.get(new_url)
start_date = "2025-09-22"
end_date = "2025-11-22"
# 等待日期选择器容器出现
date_picker = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, ".ant-picker-range"))
)
# 定位两个 input(根据 placeholder
start_input = date_picker.find_element(By.XPATH, './/input[@placeholder="开始时间"]')
end_input = date_picker.find_element(By.XPATH, './/input[@placeholder="结束时间"]')
# 使用 JavaScript 设置值并触发事件
driver.execute_script(f"arguments[0].value = '{start_date}'; arguments[0].dispatchEvent(new Event('input'));", start_input)
driver.execute_script(f"arguments[0].value = '{end_date}'; arguments[0].dispatchEvent(new Event('input'));", end_input)
# 可选:再触发 change 事件(某些框架需要)
driver.execute_script("arguments[0].dispatchEvent(new Event('change'));", start_input)
driver.execute_script("arguments[0].dispatchEvent(new Event('change'));", end_input)