-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_source.py
64 lines (51 loc) · 1.88 KB
/
fetch_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
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
62
63
64
import json
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
# from webdriver_manager.firefox import GeckoDriverManager
with open('./setup.json') as fin:
setup = json.load(fin)
chrome_options = Options()
chrome_options.add_argument("--headless")
# GeckoDriverManager.install()
driver = webdriver.Chrome(
ChromeDriverManager().install(),
chrome_options=chrome_options
)
driver.get("https://www.codewars.com/users/sign_in")
usernameElem = driver.find_element_by_id("user_email")
passwordElem = driver.find_element_by_id("user_password")
usernameElem.send_keys(setup['codewars']['email'])
passwordElem.send_keys(setup['codewars']['password'])
driver.find_element_by_xpath("//button[2]").click()
#########################################
#
# For Normal Accounts
#
##########################################
driver.find_element_by_xpath(
"//div[contains(@class, 'profile-pic')]").click()
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.LINK_TEXT, "Solutions")))
driver.find_element_by_link_text('Solutions').click()
#########################################
#
# For Disabled Accounts
#
##########################################
# Change the url directly
# driver.get('https://www.codewars.com/users/whyuenac/completed_solutions')
nReloads = setup['reloads_in_browser']
elem = driver.find_element_by_tag_name("body")
for _ in range(nReloads):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# .build().perform()
time.sleep(2)
with open('./source.html', 'w') as fin:
fin.write(driver.page_source)
driver.close()