Sadly Amazon’s website is riddled with inline css and inline jquery. Which allows those with a given skillset to take advantage of certain automation techniques. After reading the terms and conditions for Amazon Giveaways I determined it was not against the rules to automate getting prizes; below Ill share the code I wrote in 15 mins to go through the thousands of giveaways and enter entries resulting in multiple freebies.
Get all of the links
Your first step to automating all of the giveaways is to get a list of links for all of the active giveaways. Fortunately, http://giveawaylisting.org handles this for us. And so just run this little snippet to get a list:
wget giveawaylisting.com grep -oP '(?<=href=")http://amzn.to/\S+(?="target)' index.html | sort -u > giveaways.txt
Write Selenium Suite to Automate
#!/usr/bin/env python """ Run all the tests """ import time import unittest from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.keys import Keys class FrontendTests(unittest.TestCase): def setUp(self): """ Setup WebDriver """ self.driver = webdriver.Chrome("./chromedriver") def tearDown(self): self.driver.close() self.driver.quit() def test_do_giveaway(self): with open('giveaways.txt') as f: content = f.readlines() content = [x.strip('\n') for x in content] wait = WebDriverWait(self.driver, 5) for url in content: self.driver.get(url) # login try: email = self.driver.find_element_by_name("email") password = self.driver.find_element_by_name("password") email.send_keys('[email protected]') password.send_keys('pass') password.send_keys(Keys.RETURN) except: pass # follow try: elem = wait.until( EC.element_to_be_clickable((By.NAME, "follow")) ) elem.click() except: pass # tweet try: elem = wait.until( EC.element_to_be_clickable((By.NAME, "tweet")) ) elem.click() except: pass # click box # unfortunately this part for whatever reason is not currently working try: elem = wait.until( EC.element_to_be_clickable((By.ID, "box_click_target")) ) elem.click() bouncing_box = self.driver.find_element_by_id("submitForm") bouncing_box.submit() except: pass time.sleep(8) if __name__ == '__main__': unittest.main()