-
Notifications
You must be signed in to change notification settings - Fork 0
/
duo.py
161 lines (122 loc) · 6.47 KB
/
duo.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import chromedriver_autoinstaller
import requests
import json
import time
import os
chromedriver_autoinstaller.install()
chrome_options = webdriver.ChromeOptions()
# chrome_options.binary_location = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
# chrome_options.add_argument("--headless=new")
# chrome_options.add_argument("--desktop-window-1080p")
# chrome_options.add_argument("load-extension=/Users/kb/Library/Application Support/Google/Chrome/Default/Extensions/cjpalhdlnbpafiamejdnhcphjbkeiagm/1.49.2_38")
driver1 = webdriver.Chrome(options=chrome_options)
driver1.get('https://www.duolingo.com')
print("Starting browser 1...")
while True:
try:
# Find the element with the specified XPath
element = driver1.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
# Continue with your code after the element is found
# For example, you can click on the element
# Exit the loop if the element is found
break
except:
# Print a message or handle the exception as needed
print("Element not found. Retrying in 3 seconds...")
# Delay for 3 seconds before retrying
time.sleep(3)
driver2 = webdriver.Chrome(options=chrome_options)
driver2.get('https://www.duolingo.com')
print("Starting browser 2...")
while True:
try:
# Find the element with the specified XPath
element = driver2.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
# Continue with your code after the element is found
# For example, you can click on the element
# Exit the loop if the element is found
break
except:
# Print a message or handle the exception as needed
print("Element not found. Retrying in 3 seconds...")
# Delay for 3 seconds before retrying
time.sleep(3)
driver3 = webdriver.Chrome(options=chrome_options)
driver3.get('https://www.duolingo.com')
print("Starting browser 3...")
while True:
try:
# Find the element with the specified XPath
element = driver3.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
# Continue with your code after the element is found
# For example, you can click on the element
# Exit the loop if the element is found
break
except:
# Print a message or handle the exception as needed
print("Element not found. Retrying in 3 seconds...")
# Delay for 3 seconds before retrying
time.sleep(1)
is_first_iteration = True
while True:
print("Reopening lesson...")
reopen = driver1.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div/div/button")
reopen.click()
print("Reopening lesson 2...")
reopen = driver2.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div/div/button")
reopen.click()
print("Reopening lesson 3...")
reopen = driver3.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div/div/button")
reopen.click()
time.sleep(3)
print("Reopening lesson again...")
reopen2 = driver1.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div[2]/div/div[1]/div/a")
reopen2.click()
print("Reopening lesson again 2...")
reopen2 = driver2.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div[2]/div/div[1]/div/a")
reopen2.click()
print("Reopening lesson again 3...")
reopen2 = driver3.find_element(By.XPATH, "//*[@id='root']/div[2]/div/div[2]/div/div[2]/div[1]/section[2]/div/div[11]/div[2]/div/div[1]/div/a")
reopen2.click()
time.sleep(10)
if is_first_iteration:
print("Opening script...")
with open('script.txt', 'r') as file:
script = file.read()
print("Executing script...")
driver1.execute_script(script)
print("Executing script 2...")
driver2.execute_script(script)
print("Executing script 3...")
driver3.execute_script(script)
time.sleep(5)
print("Solving...")
start = driver1.find_element(By.ID, "solveAllButton")
start.click()
print("Solving 2...")
start = driver2.find_element(By.ID, "solveAllButton")
start.click()
print("Solving 3...")
start = driver3.find_element(By.ID, "solveAllButton")
start.click()
is_first_iteration = False
while True:
try:
# Find the element with the specified XPath
element = driver1.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
element = driver2.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
element = driver3.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div[2]/div/div[1]/div/div[2]')
# Continue with your code after the element is found
# For example, you can click on the element
time.sleep(1)
# Exit the loop if the element is found
break
except:
# Print a message or handle the exception as needed
print("Element not found. Retrying in 1 second...")
# Delay for 3 seconds before retrying
time.sleep(1)