-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
149 lines (126 loc) · 4.26 KB
/
main.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
import time
from random import randint
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from threading import Thread
BUTTON_PATH = 'button.wn9odt-0:nth-child(1)'
MAIN_URL = 'https://coinmarketcap.com/currencies/safememe/'
clicked_count = 0
class C_Thread:
def __init__(self, index, thread) -> None:
self.index = index
self.thread = thread
pass
def get_firefox_capabilities():
open_proxy_list = open("proxies.txt", "r")
proxy_list = open_proxy_list.read()
proxies_length = len(proxy_list.split("\n"))
proxy_info = proxy_list.split("\n")[randint(0, proxies_length - 1)]
proxy_ip = proxy_info.split(":")[0]
proxy_port = proxy_info.split(":")[1]
PROXY = f"{proxy_ip}:{proxy_port}"
firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['proxy'] = {
"proxyType": "MANUAL",
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY
}
return firefox_capabilities
def main(browser: WebDriver) -> bool:
print('Running process')
try:
# browser.execute_script('localStorage.clear()')
# browser.delete_all_cookies()
# browser.refresh()
browser.get(MAIN_URL)
except Exception as e:
# print("exception 1 {}".format(e))
return False
good_button = None
scroll_to = 0
count = 0
while good_button is None:
try:
good_button = WebDriverWait(browser, 1).until(
EC.presence_of_element_located((By.CSS_SELECTOR, BUTTON_PATH))
)
print(good_button)
except:
scroll_to = scroll_to + 400
browser.execute_script('window.scrollTo(0, {})'.format(scroll_to))
if count > 8:
# print("exception 3")
return False
# print('retrying...')
count = count + 1
time.sleep(2)
try:
elt = browser.find_element_by_css_selector('.cmc-cookie-policy-banner__close')
elt.click()
except:
print()
try:
good_button.click()
print('clicked')
browser.execute_script('localStorage.clear()')
browser.delete_all_cookies()
time.sleep(5)
return True
except Exception as e:
# print("exception 2 {}".format(e))
return False
def RepresentsInt(s):
try:
int(s)
return True
except ValueError:
return False
if __name__ == '__main__':
broswer_count = 1
click_count = 3
live_thread_count = 0
broswer_count = input("How many browser can you run? \n(defualt 1, max 3): ")
if RepresentsInt(broswer_count):
broswer_count = int(broswer_count)
else:
broswer_count = 1
if broswer_count > 3:
broswer_count = 3
print(f"broswer_count {broswer_count}")
threads = []
browsers = []
for i in range(0, broswer_count):
firefox_capabilities = get_firefox_capabilities()
browser = webdriver.Firefox(capabilities=firefox_capabilities)
# browser = webdriver.Firefox()
# browser.get(MAIN_URL)
browsers.append(browser)
def get_browser_index() -> int:
for i in range(0, 3):
exists = False
for t in threads:
if t.index is i:
exists = True
if not exists:
return i
while True:
temp = []
if live_thread_count < broswer_count:
browser_index = get_browser_index()
thread: Thread = Thread(target=main, args=(browsers[browser_index], ))
thread.start()
threads.append(C_Thread(browser_index, thread))
live_thread_count = live_thread_count + 1
browser_index = browser_index + 1
for t in threads:
if t.thread.is_alive():
temp.append(C_Thread(t.index, t.thread))
threads = temp
live_thread_count = len(threads)
time.sleep(randint(1, 4))