Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.25 KB | None | 0 0
  1. import requests, re, json, time, random
  2. requests.packages.urllib3.disable_warnings()
  3.  
  4. # Created by Alex Beals
  5. # Last updated: February 20, 2016
  6.  
  7. base_url = "https://polldaddy.com/poll/"
  8. redirect = ""
  9.  
  10. useragents = []
  11. current_useragent = ""
  12.  
  13. proxies = []
  14. current_proxy = {"http":""}
  15. current_proxy_num = -1
  16.  
  17.  
  18. def get_all_useragents():
  19.     f = open("useragent.txt", "r")
  20.     for line in f:
  21.         useragents.append(line.rstrip('\n').rstrip('\r'))
  22.     f.close()
  23.  
  24. def choose_useragent():
  25.     k = random.randint(0, len(useragents)-1)
  26.     current_useragent = useragents[k]
  27.     #print current_useragent
  28.  
  29. def get_all_proxies():
  30.     f = open("proxy.txt", "r")
  31.     for line in f:
  32.         proxies.append(line.rstrip('\n').rstrip('\r'))
  33.     f.close()
  34.  
  35. def choose_proxy():
  36.     k = random.randint(0, len(proxies)-1)
  37.     current_num = k
  38.     current_proxy["http"] = proxies[k]
  39.  
  40.  
  41. def vote_once(form, value):
  42.     c = requests.Session()
  43.     #Chooses useragent randomly
  44.     choose_useragent()
  45.     redirect = {"Referer": base_url + str(form) + "/", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "User-Agent": current_useragent, "Upgrade-Insecure-Requests":"1", "Accept-Encoding": "gzip, deflate, sdch", "Accept-Language": "en-US,en;q=0.8"}
  46.    
  47.     # Chooses proxy randomly
  48.     choose_proxy()
  49.     try:
  50.         init = c.get(base_url + str(form) + "/", headers=redirect, verify=False, proxies=current_proxy)
  51.     except:
  52.         print "error with proxy"
  53.         #proxies.remove(current_proxy_num)
  54.         return None
  55.  
  56.     # Search for the data-vote JSON object
  57.     data = re.search("data-vote=\"(.*?)\"",init.text).group(1).replace('"','"')
  58.     data = json.loads(data)
  59.     # Search for the hidden form value
  60.     pz = re.search("type='hidden' name='pz' value='(.*?)'",init.text).group(1)
  61.     # Build the GET url to vote
  62.     request = "https://polldaddy.com/vote.php?va=" + str(data['at']) + "&pt=0&r=0&p=" + str(form) + "&a=" + str(value) + "%2C&o=&t=" + str(data['t']) + "&token=" + str(data['n']) + "&pz=" + str(pz)
  63.     try:
  64.         send = c.get(request, headers=redirect, verify=False, proxies=current_proxy)
  65.     except:
  66.         print "error with proxy"
  67.         #proxies.remove(current_proxy_num)
  68.         return None
  69.    
  70.     return ("revoted" in send.url)
  71.  
  72. def vote(form, value, times, wait_min = None, wait_max = None):
  73.     global redirect
  74.     # For each voting attempt
  75.     for i in xrange(1, times+1):
  76.         b = vote_once(form, value)
  77.         # If successful, print that out, else try waiting for 60 seconds (rate limiting)
  78.         if not b:
  79.             # Randomize timing if set
  80.             if wait_min and wait_max:
  81.                 seconds = random.randint(wait_min, wait_max)
  82.             else:
  83.                 seconds = 3
  84.  
  85.             print "Voted (time number " + str(i) + ")!"
  86.             time.sleep(seconds)
  87.         else:
  88.             print "Locked.  Sleeping for 60 seconds."
  89.             i-=1
  90.             time.sleep(60)
  91.  
  92. # Initialize these to the specific form and how often you want to vote
  93. poll_id = 9658266
  94. answer_id = 44171145
  95. number_of_votes = 1000
  96. wait_min = None
  97. wait_max = None
  98.  
  99. get_all_proxies()
  100. get_all_useragents()
  101. vote(poll_id, answer_id, number_of_votes, wait_min, wait_max)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement