-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbet365_browser.py
More file actions
310 lines (266 loc) · 11.5 KB
/
bet365_browser.py
File metadata and controls
310 lines (266 loc) · 11.5 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import os
import time
from selenium import webdriver
import chromedriver_autoinstaller
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import keyboard
import re
class Browser:
def __init__(self):
self.driver = []
self.lobby_table = []
def open(self):
dirr = os.path.abspath(os.curdir).rsplit("\\", 1)[0] + "\\userdata"
options = Options()
options.add_argument("--disable-infobars")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-blink-features")
options.add_argument("--disable-gpu")
options.add_argument("excludeSwitches")
options.add_argument(r"user-data-dir={}".format(dirr))
options.add_experimental_option(
"excludeSwitches", ['enable-automation', 'enable-logging'])
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--remote-debugging-port=9222")
# options.add_experimental_option("debuggerAddress", "127.0.0.1:9230")
self.driver = webdriver.Chrome(
chromedriver_autoinstaller.install(), options=options)
# driver.maximize_window()
self.driver.get('https://casino.bet365.com/Play/LiveRoulette')
time.sleep(5)
os.system('cls')
print("\033[95m" + "=== INFO ===" + "\033[0m")
print("\033[95m" + "After you login, Press 'Q' to continue" + "\033[0m")
print("\033[95m" + "=== Bet365 ===" + "\033[0m")
print("\nQ: pressed continuing...")
while True:
if keyboard.is_pressed("q"):
break
print("Bet365 Automatic Roulette Bot ver.10.0")
self.driver.implicitly_wait(0)
open("results.html", "w", encoding="utf8").write(
self.driver.page_source)
frame1 = self.single_item(
'//iframe[@class="inline-games-page-component__game-frame "]')
self.driver.switch_to.frame(frame1)
frame = self.single_item('//iframe[@id="gamecontent"]')
self.driver.switch_to.frame(frame)
time.sleep(2)
# self.click_item('//div[@class="close-button header__close-button"]')
self.close_page()
time.sleep(2)
self.switch_tabs()
# self.click_item('//div[@class="lobby-category-item__name"][text()="Roulette"]')
def single_item(self, xpath):
try:
return self.driver.find_element(By.XPATH, xpath)
except:
# print("Item doesn't exist :", xpath)
return None
def multi_items(self, xpath):
try:
return self.driver.find_elements(By.XPATH, xpath)
except:
print("Item doesn't exist :", xpath)
return None
def click_item(self, xpath):
try:
self.single_item(xpath).click()
except:
#print("None clickable :", xpath)
print("None clickable #1")
def sub_item(self, item, xpath):
return item.find_element(By.XPATH, xpath)
def get_history_numbers(self, xpath, cnt): ########### modify the number and symbol
ii = 0
_series_que = [[], []]
while True:
_series_que[ii].clear()
for kp in range(cnt):
try:
_item = self.single_item(xpath + f'/div[{kp+1}]/div/div').text
except:
return None
if _item.isdigit():
_series_que[ii].append(int(_item))
else:
try:
_item = self.single_item(xpath + f'/div[{kp+1}]/div[2]/div').text
# print("------------------ covered number----------------")
if _item.isdigit():
_series_que[ii].append(int(_item))
else:
_series_que[ii].append(-1)
except:
_series_que[ii].append(-1)
ii = (ii+1) % 2
if _series_que[0] == _series_que[1]:
return _series_que[0].copy()
time.sleep(0.1)
def get_numbers_from_dashboard(self, index):
return self.get_history_numbers(f'(//div[@class="lobby-table__container"])[position() = {index + 1}]//div[contains(@class,"roulette-history")]', 10)
def get_numbers_from_game(self):
while True:
xx = self.get_history_numbers('//div[@class="roulette-game-area__history-line"]/div', 10)
if not xx:
print("get numnber from game error occurred!")
time.sleep(0.2)
continue
break
return xx
def close_page(self):
self.click_item('//div[@class="close-button header__close-button"]')
def get_roullete_name(self, index):
try:
return self.single_item(f'(//div[@class="lobby-table__container"])[position() = {index + 1}]//div/div[@class="lobby-table__name-container"]').text
except:
pass
return "No name"
def switch_tabs(self):
# print("-------------------------------switch ----------------------------------")
# skip_list.clear()
sr_str = ["bet365 Exclusive", "Roulette"] # "Poker", "GAME SHOWS",
for item_txt in sr_str:
# .format(item_txt))
self.click_item(
f'//div[@class="lobby-category-item__name"][text()="{item_txt}"]')
time.sleep(0.5)
time.sleep(2)
def refresh_lobby_table(self):
self.lobby_table = self.multi_items('//div[@class="lobby-table__container"]')
return len(self.lobby_table)
def join_roulette(self, index):
self.close_reality_check()
try:
element = self.multi_items('//div[@class="lobby-table__container"]')[index].find_element(By.XPATH, './../../..')
self.driver.execute_script('arguments[0].scrollIntoView(true);', element)
# driver.execute_script("window.scrollBy(0,0)","")
html = self.driver.find_element(by=By.TAG_NAME, value='html')
html.send_keys(Keys.PAGE_UP)
html.send_keys(Keys.PAGE_UP)
element.click()
except Exception as e:
print(e)
print(f"Failed to join in Roulette {index}, Try again")
time.sleep(3)
# pass
def close_mega_fire_modal(self):
try:
time.sleep(0.3)
self.single_item('(//div[@class="modal-body"])').find_elements(By.TAG_NAME, "use")[0].click()
time.sleep(0.5)
# print(close)
# close.click()
except Exception as e:
print("Error to close the modal of mega fire blaze roulette live!")
pass
def get_chip_reference(self):
# _chips_list = [None,
# 'chipsPanel.chip50',
# 'chipsPanel.chip100',
# 'chipsPanel.chip500',
# 'chipsPanel.chip1000',
# 'chipsPanel.chip2500',
# 'chipsPanel.chip10000',
# 'chipsPanel.chip50000',
# 'chipsPanel.chip100000',
# None]
try:
# find(By.XPATH, f'(//div[@class="controls-panel__chip-panel"])').find_elements(
# By.TAG_NAME, "svg")[_index].click()
ppp = self.single_item('(//div[@class="controls-panel__chip-panel"])').find_elements(By.TAG_NAME, "svg")
_chips_list = []
for item in ppp:
# print(item)
val = item.get_attribute('data-automation-locator')
# print(val)
_chips_list.append(val)
except Exception as e:
return None
time.sleep(0.1)
res = []
for _chip in _chips_list:
if _chip == None:
res.append(0)
else:
res.append(int(re.findall('[0-9]+', _chip)[0]))
return res
def get_balance(self):
try:
dollar = self.single_item('(//div[@class="account-panel__section account-panel__balance-section"]/div[1]/div[2]/div/div)').text
except:
dollar = "Money 0.00"
return float(re.findall('[0-9.]+', dollar.replace(',',''))[0])
def select_chip(self, _index):
try:
self.single_item(f'(//div[@class="controls-panel__chip-panel"])').find_elements(By.TAG_NAME, "svg")[_index].click()
except Exception as e:
return False
# print("select chip ok")
time.sleep(0.3)
return True
def close_reality_check(self):
while True:
flag_close = False
try:
time_limit_modal = self.single_item('(//div[@class="session-modals"])')
time_limit_modal.find_elements(By.TAG_NAME, "button")[1].click()
# time.sleep(0.3)
print(">>>>>>>>>>>>>>> Reality check modal is closed")
flag_close = True
except:
pass
try:
inactivity = self.single_item('(//div[@class="game-modals"])')
inactivity.find_elements(By.TAG_NAME, "button")[0].click()
# time.sleep(0.3)
print(">>>>>>>>>>>>>>> Inactivity modal is closed")
flag_close = True
except:
pass
try:
inactivity = self.single_item('(//div[@class="toaster-modals"])')
inactivity.find_elements(By.TAG_NAME, "button")[0].click()
# time.sleep(0.3)
print(">>>>>>>>>>>>>>> Toaster modal is closed")
flag_close = True
except:
pass
if flag_close:
time.sleep(1)
continue
break
def click_key(self, _key):
# return
_cls_name = {
"Low": "roulette-table-cell_side-low",
"High": "roulette-table-cell_side-high",
"Odd": "roulette-table-cell_side-odd",
"Even": "roulette-table-cell_side-even",
"Red": "roulette-table-cell_side-red",
"Black": "roulette-table-cell_side-black",
"Zero": "roulette-table-cell_straight-0",
"Zero0": "roulette-table-cell_straight-00",
"Bonus": "roulette-table-cell_straight-bonus",
"1st_Dozen" : "roulette-table-cell_side-first-dozen",
"2nd_Dozen" : "roulette-table-cell_side-second-dozen",
"3rd_Dozen" : "roulette-table-cell_side-third-dozen",
"Bottom_Column" : "roulette-table-cell_side-bottom-column",
"Middle_Column" : "roulette-table-cell_side-middle-column",
"Top_Column" : "roulette-table-cell_side-top-column"
}
# print(20*'-----------')
# for key in _cls_name.keys():
try:
self.single_item('(//div[@class="roulette-game-area__main-digital-table"])').find_element(By.CLASS_NAME, _cls_name[_key]).click()
time.sleep(0.3)
# print(f"click {_key}")
# print(item)
except Exception as e:
print(f"error for clicking the key {_key}")
print(e)
# print(20*'-----------')
# browser = Browser()
# browser.open('https://casino.bet365.com/Play/LiveRoulette')