-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.py
51 lines (37 loc) · 1.5 KB
/
connect.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
import time
import json
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
SLEEP_BETWEEN_PAGES = 5
def get_driver() -> WebDriver:
chrome_path = "/usr/local/bin/chromedriver"
options = Options()
options.headless = False
caps = DesiredCapabilities.CHROME
caps["goog:loggingPrefs"] = {"performance": "ALL"}
driver = webdriver.Chrome(chrome_path, options=options, desired_capabilities=caps)
driver.get("https://www.geoguessr.com")
driver.implicitly_wait(SLEEP_BETWEEN_PAGES)
return driver
def login(driver: WebDriver):
with open("./cookies.json", "r") as f:
cookies = json.load(f)
cookies_to_set = ["G_ENABLED_IDPS", "_ncfa", "devicetoken"]
for cookie_name in cookies_to_set:
driver.add_cookie({"name": cookie_name, "value": cookies[cookie_name]})
driver.get("https://www.geoguessr.com/streaks")
accept_cookies = driver.find_element(By.XPATH, "//div[@id='accept-choices']")
accept_cookies.click()
def launch_game(driver: WebDriver):
country_streaks = driver.find_element(
By.XPATH, "//a[@data-qa='play-country-streak']"
)
country_streaks.click()
play_button = driver.find_element(
By.XPATH, "//button[@data-qa='start-streak-game-button']"
)
play_button.click()
time.sleep(SLEEP_BETWEEN_PAGES)