-
Notifications
You must be signed in to change notification settings - Fork 0
/
source.py
34 lines (27 loc) · 1.16 KB
/
source.py
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
from selenium import webdriver
from selenium.webdriver.common.by import By
class Source:
def __init__(self):
options = webdriver.ChromeOptions()
options.add_argument("headless")
self.driver = webdriver.Chrome(options = options)
self.login_cookie = None
def get_source(self, login_cookie, submission_id):
source_url = "https://www.acmicpc.net/source/" + str(submission_id)
self.driver.get(source_url)
if self.login_cookie != login_cookie:
self.login_cookie = login_cookie
self.driver.add_cookie(login_cookie)
self.driver.get(source_url) # retry loading the page with the cookie
textarea = self.driver.find_element(By.NAME, "source")
source = textarea.get_attribute("value")
return source
# from login import Login
# from getpass import getpass
# loginObject = Login()
# user_id = input("Input id: ")
# password = getpass("Input password: ")
# login_cookie = loginObject.login(user_id, password)
# sourceEngine = Source()
# print(sourceEngine.get_source(login_cookie, 56892412))
# print(sourceEngine.get_source(login_cookie, 54530876))