Skip to content

Instantly share code, notes, and snippets.

@sleeyax
Created April 24, 2019 22:39
Show Gist options
  • Save sleeyax/e155cefd77dbebb371a1b8c4b2c3514d to your computer and use it in GitHub Desktop.
Save sleeyax/e155cefd77dbebb371a1b8c4b2c3514d to your computer and use it in GitHub Desktop.
strawpoll.me voting bot
import requests
import re
import random
import sys
class StrawPoll:
def __init__(self, id):
self.url = "https://www.strawpoll.me/%s" % id
self.session = requests.session()
self.headers = {
"User-Agent": self.generate_ua(),
"Referer": self.url,
"X-Requested-With": "XMLHttpRequest"
}
def generate_ua(self):
return random.choice([
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
"Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
"Opera/9.80 (Android; Opera Mini/36.2.2254/119.132; U; id) Presto/2.12.423 Version/12.16"
])
def get_security_token(self, html):
matches = re.search(r"name=\"security-token\" type=\"hidden\" value=\"(.+?)\"", html)
return matches.group(1)
def get_poll_id(self, name, html):
matches = re.findall(r"name=\"options\"\s+value=\"(\d+?)\".*?span>(.+?)<", html, re.MULTILINE | re.DOTALL)
return [match for match in matches if match[1].lower() == name.lower()][0][0]
def get_authtoken(self, html):
matches = re.search(r"id=\"field-authenticity-token\" name=(\".+?\")", html)
return matches.group(1)
def iterate_proxies(self, file="proxies.txt"):
for line in open(file, "r"):
yield line.strip('\n')
def vote(self, name):
for proxy in self.iterate_proxies():
print("Using proxy " + proxy)
proxies = {
"http": "http://" + proxy,
"https": "https://" + proxy
}
print("Scraping tokens...")
try:
r = self.session.get(self.url, headers=self.headers, proxies=proxies)
html = r.text
payload = {
"security-token": self.get_security_token(html),
"options": self.get_poll_id(name, html),
self.get_authtoken(html): ""
}
print("Sending vote for poll id {0} ({1})...".format(payload["options"], name))
r = self.session.post(self.url, headers=self.headers, data=payload, proxies=proxies)
if r.json()["success"] == "success":
print("Vote sent successfully!")
else:
print("Oops, vote not sent :(")
except requests.exceptions.RequestException:
print("Failed to connect to proxy")
except KeyboardInterrupt:
print("Quit")
sys.exit()
except Exception as ex:
print("Unknown error: " + str(ex))
poll = StrawPoll(1337)
poll.vote("Midnight")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment