from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import pyperclip import time def get_problem(problemId: int): baseURL = "https://www.luogu.com.cn/problem/P" reqURL = baseURL + str(problemId) try: driver = webdriver.Chrome() driver.minimize_window() driver.get(reqURL) # Wait for the button to be clickable button = WebDriverWait(driver, 10).until( EC.element_to_be_clickable( ( By.XPATH, '//*[@id="app"]/div[2]/main/div/section[2]/section/div/div[1]/a[1]', ) ) ) # Click the button button.click() # Wait for a short time for the text to be copied (adjust as needed) time.sleep(2) # Use pyperclip to get the clipboard content (simulated) clipboard_text = pyperclip.paste() driver.quit() # Write down to the file file_name = str(problemId) + ".txt" with open(file_name, "w", encoding="utf-8") as file: file.write(clipboard_text) except Exception as e: print(f"An error occurred: {e}") for i in range(8346, 10100): get_problem(i) time.sleep(30)