正巧最近在做一份问卷,心血来潮就码了这么一个东西,仅供玩乐,切勿滥用.
目前只是一个简单的模型,具体的题型设置还需要自己去修改一下代码.
安装好需要的Python的各个模块以及Chromedriver就OK了
下面代码的题型对应的是我自己问卷的题目设置,所以,如果要使用,还要根据具体情况修改
注:每填写完一份问卷最后把延时放久一些,太快问卷星会刷出验证码.验证码的识别以后还记得就来加上.
#coding=utf-8
import time
import json
import random
import base64
import requests
import urllib
from PIL import Image
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def autoSelect():
#将问卷星网站放在下面
driver.get('https://www.wjx.cn/m/-------.aspx')
key_1=str(random.randint(1,4))
key_4='0'
#单选题,因为和后面的题有逻辑关系,记下随机值key_1
xpath1 = '//*[@id="div1"]/div[2]/div[%s]'%key_1
answer_1 = driver.find_elements_by_xpath(xpath1)[0]
answer_1.click()
xpath2 = '//*[@id="div2"]/div[2]/div[%s]' % str(random.randint(1,2))
answer_2 = driver.find_elements_by_xpath(xpath2)[0]
answer_2.click()
if key_1=='1' :
xpath3 = '//*[@id="div4"]/div[2]/div[%s]' % str(random.randint(1,3))
answer_3 = driver.find_elements_by_xpath(xpath3)[0]
answer_3.click()
else:
key_4=str(random.randint(1,3))
xpath4 = '//*[@id="div4"]/div[2]/div[%s]' % key_4
answer_4 = driver.find_elements_by_xpath(xpath4)[0]
answer_4.click()
if key_4=='1':
xpath6 = '//*[@id="div6"]/div[2]/div[%s]' % str(random.randint(1,4))
answer_6 = driver.find_elements_by_xpath(xpath6)[0]
answer_6.click()
if key_4=='2' :
xpath5 = '//*[@id="div5"]/div[2]/div[%s]' % str(random.randint(1,4))
answer_5 = driver.find_elements_by_xpath(xpath5)[0]
answer_5.click()
if key_4=='3' :
xpath7 = '//*[@id="div7"]/div[2]/div[%s]' % str(random.randint(1,4))
answer_7 = driver.find_elements_by_xpath(xpath7)[0]
answer_7.click()
xpath8 = '//*[@id="div8"]/div[2]/div[%s]' % str(random.randint(1,3))
answer_8 = driver.find_elements_by_xpath(xpath8)[0]
answer_8.click()
#排序题
qList_9 = [str(x) for x in range(1,9)]
print qList_9
random.shuffle(qList_9)
print qList_9
for i in qList_9:
xpath9 = '//*[@id="div9"]/ul/li[%s]/div[1]' % i
answer_9 = driver.find_elements_by_xpath(xpath9)[0]
answer_9.click()
#矩阵量表
for i in range(1,9):
xpath11 = '//*[@id="drv11_%s"]/td[%s]/a'%(str(i),str(random.randint(1,6)))
answer_11 = driver.find_elements_by_xpath(xpath11)[0]
answer_11.click()
xpath12 = '//*[@id="div12"]/div[2]/div[%s]' % str(random.randint(1,3))
answer_12 = driver.find_elements_by_xpath(xpath12)[0]
answer_12.click()
#矩阵量表
for i in range(1,16):
xpath13 = '//*[@id="drv13_%s"]/td[%s]'%(str(i),str(random.randint(1,4)))
answer_13 = driver.find_elements_by_xpath(xpath13)[0]
answer_13.click()
xpath14 = '//*[@id="div14"]/div[2]/div[%s]' % str(random.randint(1,3))
answer_14 = driver.find_elements_by_xpath(xpath14)[0]
answer_14.click()
#提交
submit = driver.find_elements_by_css_selector('#ctlNext')[0]
submit.click()
time.sleep(0.5)
if __name__ == '__main__':
driver = webdriver.Chrome()
#循环4次
for index in range(1,5):
autoSelect()