You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.8 KiB
50 lines
1.8 KiB
from selenium import webdriver
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
from time import sleep
|
|
|
|
def create_driver():
|
|
""" 创建并配置 WebDriver 实例 """
|
|
options = webdriver.EdgeOptions()
|
|
#options.add_argument("--headless") # 无界面模式
|
|
options.add_argument("--start-maximized") # 最大化窗口
|
|
options.add_argument("--disable-notifications") # 禁用通知
|
|
options.add_argument("user-data-dir=C:/Users/JJM/AppData/Local/Microsoft/Edge/User Data/Default")
|
|
options= webdriver.EdgeOptions()
|
|
options.add_experimental_option("detach", True)
|
|
driver = webdriver.Edge(options=options)
|
|
return driver
|
|
|
|
def login():
|
|
driver = create_driver()
|
|
try:
|
|
driver.get("https://contest.cdec.org.cn/#/signin")
|
|
# 使用显式等待确保元素可交互
|
|
sleep(2)
|
|
|
|
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[1]/div/div/div/input').send_keys('15367278097',Keys.ENTER)
|
|
sleep(2)
|
|
|
|
|
|
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[2]/div/div/div/input').send_keys('123456',Keys.ENTER)
|
|
sleep(2)
|
|
driver.find_element(By.XPATH,'//*[@id="app"]/div/div[3]/div/form/div[3]/div[1]/div/div/button').click()
|
|
sleep(2) # 简单延时等待操作完成
|
|
finally:
|
|
pass
|
|
|
|
|
|
|
|
def main():
|
|
with ThreadPoolExecutor(max_workers=10) as executor: # 同时启动10个线程
|
|
futures = [executor.submit(login) for _ in range(10)]
|
|
for future in futures:
|
|
future.result()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|