-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCookieClicker.py
48 lines (36 loc) · 1.51 KB
/
CookieClicker.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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
service = Service(executable_path='/Users/lucasha/Personal Projects/web scraper/chromedriver')
driver = webdriver.Chrome(service=service)
driver.get('https://orteil.dashnet.org/cookieclicker/')
cookie_id = 'bigCookie'
cookies_id = "cookies"
product_price_prefex = "productPrice"
product_prefix = "product"
WebDriverWait(driver,5).until(
EC.presence_of_all_elements_located((By.XPATH, "//*[contains(text(), 'English')]"))
)
language = driver.find_element(By.XPATH, "//*[contains(text(), 'English')]")
language.click()
WebDriverWait(driver,5).until(
EC.presence_of_all_elements_located((By.ID,cookie_id))
)
cookie = driver.find_element(By.ID, cookie_id)
while True:
cookie.click()
cookies_count = driver.find_element(By.ID, cookies_id).text.split(" ")[0]
cookies_count = int(cookies_count.replace(",",""))
for i in range(4):
product_price = driver.find_element(By.ID,product_price_prefex + str(i)).text.replace(",","")
if not product_price.isdigit():
continue
product_price = int(product_price)
if cookies_count >= product_price:
product = driver.find_element(By.ID, product_prefix + str(i))
product.click()
break