-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvote-troller.py
More file actions
96 lines (81 loc) · 2.52 KB
/
vote-troller.py
File metadata and controls
96 lines (81 loc) · 2.52 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
"""The automated vote trolling module."""
import config
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from seleniumwire import webdriver
from chromedriver_py import binary_path
def vote_for_names(driver, names):
"""Take a list of names and vote for each one."""
# Sleep to make sure items are visible
time.sleep(2)
for name in names:
# Find the root element with the name
root_el = driver.find_element(
By.XPATH, config.root_element_xpath.replace('NAME', name)
)
# Sleeping to avoid misclick
time.sleep(0.5)
# Get the root element location
location = root_el.location
# Scroll to the element
driver.execute_script(
"""
window.scrollTo(
{
top: arguments[0],
left: 0,
behavior: 'instant'
}
);
""",
location['y']
)
# Find the button
button_el = driver.find_element(
By.XPATH,
config.root_element_xpath.replace('NAME', name) +
config.button_xpath
)
# Click it
WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(button_el)
).click()
def cast_votes():
"""Create a browser and cast the votes."""
# Web driver options
options = {
'proxy': {
'http': config.http_proxy_string,
'https': config.https_proxy_string,
'no_proxy': 'localhost,127.0.0.1'
}
}
# Create the webdriver
chrome_options = Options()
# chrome_options.add_argument("--headless") # Uncomment for headless mode
driver = webdriver.Chrome(
options=chrome_options,
seleniumwire_options=options,
executable_path=binary_path
)
driver.implicitly_wait(10)
try:
# Visit the URL of the poll
driver.get(config.poll_url)
# Vote for the names
vote_for_names(driver, config.names)
time.sleep(4)
print('Voted')
except Exception as e:
print(e)
finally:
# Close the web driver completely (needed for rotating proxy to work)
driver.close()
driver.quit()
driver = None
# Loop the specified number of times and cast the votes
for i in range(0, config.num_of_votes):
cast_votes()