-
Notifications
You must be signed in to change notification settings - Fork 3
/
VotingAPP.py
142 lines (110 loc) · 4.45 KB
/
VotingAPP.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
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.proxy import Proxy, ProxyType
import os
import time
import datetime
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from os import listdir
from os.path import isfile, join
from selenium.common.exceptions import NoSuchElementException
import random
co = webdriver.ChromeOptions()
co.add_experimental_option("excludeSwitches",
["ignore-certificate-errors", "safebrowsing-disable-download-protection",
"safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])
co.add_argument('--disable-infobars')
co.add_argument('--disable-extensions')
co.add_argument('--profile-directory=Default')
co.add_argument("--incognito")
co.add_argument("--disable-plugins-discovery")
co.add_argument("--start-maximized")
def get_proxies(co=co):
with open("proxy.txt") as f:
content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
PROXIES = [x.strip() for x in content]
return PROXIES
def proxy_driver(PROXIES, co=co):
prox = Proxy()
if PROXIES:
pxy = PROXIES[-1]
else:
print("--- Proxies used up (%s)" % len(PROXIES))
PROXIES = get_proxies()
proxy = Proxy()
proxy.proxyType = ProxyType.MANUAL
proxy.autodetect = False
proxy.httpProxy = proxy.sslProxy = proxy.socksProxy = pxy
co.Proxy = proxy
co.add_argument("ignore-certificate-errors")
driver = webdriver.Chrome(executable_path="D:/chromedriver.exe",chrome_options=co)
return driver
def firstsite(driver):
item_url = "https://www.research.net/r/ClimateControlExperts"
driver.get(item_url)
delay = 5
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'checkbox-button-container')))
print("Page is ready!")
checkboxs = driver.find_elements_by_css_selector("span.checkbox-button-label-text.question-body-font-theme.user-generated")
for check in checkboxs:
driver.execute_script("arguments[0].click();", check)
time.sleep(1)
submit = driver.find_element_by_tag_name("button")
driver.execute_script("arguments[0].click();", submit)
time.sleep(1)
except TimeoutException:
print("Page Loading took too much time!")
def secondsite(driver):
item_url = "https://www.research.net/r/NationalTechnicalInstitute"
driver.get(item_url)
delay = 5
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.CLASS_NAME, 'checkbox-button-container')))
print("Page is ready!")
checkboxs = driver.find_elements_by_css_selector("span.checkbox-button-label-text.question-body-font-theme.user-generated")
for check in checkboxs:
driver.execute_script("arguments[0].click();", check)
time.sleep(1)
submit = driver.find_element_by_tag_name("button")
driver.execute_script("arguments[0].click();", submit)
time.sleep(1)
except TimeoutException:
print("Page Loading took too much time!")
def main():
ALL_PROXIES = get_proxies()
# --- YOU ONLY NEED TO CARE FROM THIS LINE ---
# creating new driver to use proxy
pd = proxy_driver(ALL_PROXIES)
# code must be in a while loop with a try to keep trying with different proxies
running = True
while running:
try:
firstsite(pd)
secondsite(pd)
new = ALL_PROXIES.pop()
pd.close()
# reassign driver if fail to switch proxy
pd = proxy_driver(ALL_PROXIES)
print("--- Switched proxy to: %s" % new)
time.sleep(1)
if len(ALL_PROXIES) == 0:
running = False
except:
new = ALL_PROXIES.pop()
#pd.close()
# reassign driver if fail to switch proxy
pd = proxy_driver(ALL_PROXIES)
print("--- Switched proxy to: %s" % new)
time.sleep(1)
if len(ALL_PROXIES) == 0:
running = False
pd.close()
if __name__ == "__main__":
main()