Quick show & tell post. How to use Python, Selenium and Chromedriver to automate the completion of a Survey Monkey survey, for good or evil.
So our company just ran a 'people's choice' employee of the year competition and sent out a Survey Monkey form for people to vote.
I wanted to see if I could automate the submission of the survey using Selenium browser automation in order to test whether it was theoretically possible to write a bot that would vote for a single individual. Turns out it only took 18 lines of Python.
import time from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.options import Options chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("-incognito") driver = webdriver.Chrome(executable_path='/Library/Python/2.7/site-packages/selenium/webdriver/chrome/chromedriver', chrome_options=chrome_options) driver.get('https://www.surveymonkey.com/s/<yoursurveyid>') time.sleep(2) nxt_btn = driver.find_element_by_name('NextButton') nxt_btn.click() time.sleep(2) vote_check = driver.find_element_by_id('linput_740142485_10_8428776065_0') vote_check.click() time.sleep(2) nxt_btn = driver.find_element_by_name('NextButton') nxt_btn.click() driver.quit()
I've put the gist up for download.
For those familiar with Selenium this is all pretty standard stuff. The script navigates the 'Next page' buttons and then clicks a specific check box that corresponds with an answer by targeting the attribute id="linput_740142485_10_8428776065_0". Obviously you could interact with any sort of field that the survey presents, this one just happened to be checkboxes.
The reason I went with Chrome's chromedriver over Selenium Webdriver's default Firefox is because I knew that the incognito mode would allow me to circumvent the cookies which track whether you have completed the survey before. However, I suspect Firefox's 'private window' feature could do the same.
You can start Chromedriver in incognito mode by passing -incognito as an option when launching the driver.
Well yes, and no. Survey Monkey has a number of options the survey creator can choose to protect their survey from abuse.
So my script is not bullet proof, but luckily it relies on the survey creator knowing how to configure those features within Survey Monkey and then also check them after the results have come in. I'm betting that for a standard competition or internal survey it's unlikely they would go to that level of scrutiny.