File size: 1,955 Bytes
45c4368
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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)