Skip to content

Instantly share code, notes, and snippets.

@nunq
Last active March 18, 2019 18:14
Show Gist options
  • Save nunq/c97d8d1765bdaabce768c891e684fe83 to your computer and use it in GitHub Desktop.
Save nunq/c97d8d1765bdaabce768c891e684fe83 to your computer and use it in GitHub Desktop.
vote bot for strawpoll.de
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from stem import Signal
from stem.control import Controller
import time
# you need geckodriver and tor
option = 1 # what to vote
boostby = 5 # boost option by around x votes
imgyes = 0 # are there images? 1 = yes, 0 = no
polladdr = "https://strawpoll.de/LINK"
ctrlportpw = "password"
failedvotes = 0
def setup():
global profile
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0")
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.socks", "127.0.0.1")
profile.set_preference("network.proxy.socks_port", 9050)
def getnewnym():
with Controller.from_port(port = 9051) as controller:
controller.authenticate(password = ctrlportpw)
print("STAT: Delaying next request")
time.sleep(3)
controller.signal(Signal.NEWNYM)
print("STAT: Requesting NEWNYM")
def drvget(addr):
global driver, profile
driver = webdriver.Firefox(profile)
driver.get(addr)
def vote():
print("STAT: Launching new instance")
drvget(polladdr)
choice = driver.find_element_by_xpath("/html/body/section[1]/div/div/div["+str(3+imgyes)+"]/div["+str(option)+"]/label")
submit = driver.find_element_by_xpath('//*[@id="votebutton"]')
choice.click()
submit.click()
print("STAT: Submitted vote")
time.sleep(1)
def getresponse():
global failedvotes
try:
print("RESP: "+driver.find_element_by_xpath("/html/body/section[1]/div/div/div["+str(4+imgyes)+"]/div[1]/span").text)
if ((driver.find_element_by_xpath("/html/body/section[1]/div/div/div["+str(4+imgyes)+"]/div[1]/span").text == "Fehler: Du hast bereits abgestimmt.") or (driver.find_element_by_xpath("/html/body/section[1]/div/div/div["+str(4+imgyes)+"]/div[1]/span").text == "Erreur: Vous avez déjà voté sur ce sondage.") or (driver.find_element_by_xpath("/html/body/section[1]/div/div/div["+str(4+imgyes)+"]/div[1]/span").text == "Error: You already voted on this poll.") ):
failedvotes += 1
except:
print("ERROR: Couldn't get response text")
print("STAT: Voting for option "+str(option)+ " at "+polladdr)
started = time.time()
for i in range(0, boostby):
setup()
getnewnym()
vote()
getresponse()
driver.close()
finished = time.time()
print("\nSTAT: Finished. Time taken: "+str(int(finished-started))+" seconds")
print("STAT: Success rate was "+str(boostby-failedvotes)+"/"+str(boostby))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment