-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
43 lines (31 loc) · 1.14 KB
/
ui.py
File metadata and controls
43 lines (31 loc) · 1.14 KB
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
from config import ACCOUNT, PASSWORD
def validate_login(username: str, passowrd: str):
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get('https://pintia.cn/auth/login')
# wait for page load
wait = WebDriverWait(driver, 10)
wait.until(lambda driver: driver.find_elements(By.TAG_NAME, 'input'))
# find all input elements
inputs = driver.find_elements(By.TAG_NAME, 'input')
username_input = inputs[0]
password_input = inputs[1]
remember_me = inputs[2]
login_button = driver.find_elements(By.TAG_NAME, 'button')[0]
# fill in the form
username_input.send_keys(username)
password_input.send_keys(passowrd)
remember_me.click()
driver.implicitly_wait(1)
login_button.click()
# TODO: auto login for netease login
while driver.current_url != 'https://pintia.cn/problem-sets/dashboard':
time.sleep(1)
cookies = driver.get_cookies()
driver.quit()
return cookies
if __name__ == '__main__':
validate_login(ACCOUNT, PASSWORD)