-
Notifications
You must be signed in to change notification settings - Fork 0
/
Automate_Websites_with_Bots.py
52 lines (40 loc) · 1.77 KB
/
Automate_Websites_with_Bots.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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager # Automatically manage ChromeDriver
import time
# Automatically set up the Chrome driver using WebDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://orteil.dashnet.org/cookieclicker/")
cookie_id = "bigCookie"
cookies_id = "cookies"
product_price_prefix = "productPrice"
product_prefix = "product"
# Wait until the language selection is present
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'English')]"))
)
# Select English as the language
language = driver.find_element(By.XPATH, "//*[contains(text(), 'English')]")
language.click()
# Wait for the cookie to be present
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.ID, cookie_id))
)
cookie = driver.find_element(By.ID, cookie_id)
# Infinite loop to click the cookie and purchase products
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_prefix + 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