Python+Selenium刷问卷星问卷

因被他人叫做填写调查问卷,想到可以用Selenium快速刷大量问卷,于是写了段代码试验了一下。因为问卷题目要求过于简单,所以代码过于浅薄,以后会添加很多功能—>>>如使用ip代理池,随机生成User-Agent来防止问卷星去重。

from selenium import webdriver
import random
import time

def parse_page(i):
    
    driver = webdriver.Chrome()
    driver.get('https://www.wenjuan.com/s/bu6BNfP/')
    time.sleep(2)
    #问题一性别
    xpath1 = '//*[@id="question_5dd503c692beb518d45e07ea"]/div[2]/div[%s]/label/span' % str(random.randint(3,4))
    answer_1 = driver.find_elements_by_xpath(xpath1)[0]
    answer_1.click()
    
    #问题二年级
    xpath2 = '//*[@id="question_5dd503c692beb518d45e07eb"]/div[2]/div[%s]/label/span' % str(random.randint(3,6))
    answer_2 = driver.find_elements_by_xpath(xpath2)[0]
    answer_2.click()
    
    #问题三专业领域
    xpath3 = '//*[@id="question_5dd503c692beb518d45e07ec"]/div[2]/div[%s]/label/span' % str(random.randint(3,9))
    answer_3 = driver.find_elements_by_xpath(xpath3)[0]
    answer_3.click()
    
    #问题四政治面貌
    xpath4 = '//*[@id="question_5dd503c692beb518d45e07ed"]/div[2]/div[%s]/label/span' % str(random.randint(3,5))
    answer_4 = driver.find_elements_by_xpath(xpath4)[0]
    answer_4.click()
   
    #问题五是否担任班干部
    xpath5 = '//*[@id="question_5dd503c692beb518d45e07ee"]/div[2]/div[%s]/label/span' % str(random.randint(3,4))
    answer_5 = driver.find_elements_by_xpath(xpath5)[0]
    answer_5.click()
    
    #问题六途径
    xpath6 = '//*[@id="question_5dd503c692beb518d45e07ef"]/div[2]/div[%s]/label/span' % str(random.randint(3,6))
    answer_6 = driver.find_elements_by_xpath(xpath6)[0]
    answer_6.click()
    
    #问题七价值观
    xpath7 = '//*[@id="question_5dd503c692beb518d45e07f0"]/div[2]/div[%s]/label/span' % str(random.randint(3,6))
    answer_7 = driver.find_elements_by_xpath(xpath7)[0]
    answer_7.click()
    
    #问题八因素
    xpath8 = '//*[@id="question_5dd503c692beb518d45e07f1"]/div[2]/div[%s]/label/span' % str(random.randint(3,6))
    answer_8 = driver.find_elements_by_xpath(xpath8)[0]
    answer_8.click()
    
    #问题九是否有必要
    xpath9 = '//*[@id="question_5dd503c692beb518d45e07f2"]/div[2]/div[%s]/label/span' % str(random.randint(3,5))
    answer_9 = driver.find_elements_by_xpath(xpath9)[0]
    answer_9.click()
 
    #问题十途径
    xpath10 = '//*[@id="question_5dd503c692beb518d45e07f3"]/div[2]/div[%s]/label/span' % str(random.randint(3,6))
    answer_10 = driver.find_elements_by_xpath(xpath10)[0]
    answer_10.click()
    
    #问题十一
    xpath11 = driver.find_element_by_xpath('//*[@id="5dd504ec92beb530d8ee1a25"]')
    xpath11.send_keys('无')
    
    #提交
    xpath12 = driver.find_element_by_xpath('//*[@id="next_button"]')
    xpath12.click()
  
    driver.quit()

if __name__ == '__main__':
    for i in range(100):
        parse_page(i)
        print('成功' + str(i) + '次')

希望对大家有些帮助,如果记得起来的话会添加其他功能