更新:第一个问卷星是我同学的,,我们组的是问卷网。。顺便附上我的完整思路(在问卷星下侧是问卷网)
前一段时间有个课程需要问卷星搜集材料信息,,但是问卷星这东西你不一个个求人哪有人愿意点进去帮你填呢,,呵呵,不行,我自己来。。。
本来想看看问卷星他的表单提交的请求方式,,奈何我太垃圾。看不懂那么庞大的js,理不清其中的思路,,既然能力不行,那只好用selenium这个自动化工具了。
先用简单的一个表单做说明吧。找一个简单的问卷
from selenium import webdriver
import time
browser = webdriver.Chrome()#声明
browser.get('https://www.wjx.cn/jq/31521246.aspx')
time.sleep(2)
for i in range(10):
browser.get('https://www.wjx.cn/jq/31521246.aspx')
browser.find_element_by_css_selector("a[rel='q1_3']").click()
time.sleep(1)
browser.find_element_by_css_selector("a[rel='q2_1']").click()
time.sleep(1)
browser.find_element_by_css_selector("a[rel='q3_2']").click()
time.sleep(1)
browser.find_element_by_id("submit_button").click()
from selenium import webdriver
import time
import random
browser = webdriver.PhantomJS()
browser.get('https://www.baidu.com')
time.sleep(2)
for i in range(200):
try:
time.sleep(5)
browser.get('https://www.wenjuan.com/s/2Uf6Fbe/')
sex=browser.find_elements_by_css_selector("a[rel='question_5bfe34cd92beb5077b5fdaec']")
index=random.randint(1,5)
if index<3:
sex[1].click()
else:
sex[0].click()
time.sleep(0.5)
grade=browser.find_elements_by_css_selector("a[rel='question_5bfe34cd92beb5077b5fdaed']")
#index=random.randint(0,3)
grade[2].click()
time.sleep(0.5)
istanguo=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaee']")
index=random.randint(1,10)
if index>6:
istanguo[0].click()
else:
istanguo[1].click()
tiaojian=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaf1']")
index=random.randint(1,13)
if index<=6:
tiaojian[0].click()
index = random.randint(1, 13)
if index<=6:
tiaojian[1].click()
index = random.randint(1, 13)
if index <= 3:
tiaojian[2].click()
if index<=8:
tiaojian[3].click()
index = random.randint(1, 13)
if index<=3:
tiaojian[4].click()
index = random.randint(1, 13)
if index <= 7:
tiaojian[5].click()
if index<=6:
tiaojian[6].click()
index = random.randint(1, 13)
if index<=9:
tiaojian[7].click()
index = random.randint(1, 13)
if index <= 9:
tiaojian[8].click()
if index<=2:
tiaojian[9].click()
index = random.randint(1, 13)
if index<=2:
tiaojian[10].click()
index = random.randint(1, 16)
if index <= 2:
tiaojian[11].click()
index = random.randint(1, 13)
if index <= 8:
tiaojian[12].click()
age= browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdaf4']")
index=random.randint(0,100)
if index<50:
age[0].click()
elif index>65:
age[2].click()
else:
age[1].click()
time.sleep(0.5)
yingxiang=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdafb']")
index=random.randint(1,10)
jud=False
if(index<=4):
yingxiang[0].click()
jud=True
index = random.randint(1, 10)
if (index <= 2):
yingxiang[1].click()
jud = True
index = random.randint(1, 10)
if (index <= 6):
jud = True
yingxiang[2].click()
index = random.randint(1, 10)
if (index <= 8):
yingxiang[3].click()
jud = True
index = random.randint(1, 10)
if (index <= 5):
yingxiang[4].click()
jud = True
if jud==False:#防止运气不好一个没选上
yingxiang[2].click()
time.sleep(0.3)
jichu=browser.find_elements_by_css_selector("a[rel='question_5bfe34ce92beb5077b5fdafd']")
index=random.randint(0,100)
if index<64:
jichu[1].click()
elif index>98:
jichu[2].click()
else:
jichu[0].click()
time.sleep(0.5)
jiehun=browser.find_elements_by_css_selector("a[rel='question_5bfe395992beb5238625321e']")
index=random.randint(0,100)
if index<65:
jiehun[2].click()
elif index>98:
jiehun[0].click()
elif index>=65 and index<=83:
jiehun[3].click()
else:
jiehun[1].click()
browser.find_element_by_id("next_button").click()
except Exception as e:
print(e)
#input.clear()
#button = browser.find_element_by_class_name('btn-search')
#button.click()
查看无误之后不想弹出窗口将chromedriver换成phantomjs或设置不跳出参数即可即可。
可以看到答题人数上涨了(切记控制速度)
如果对后端、爬虫、数据结构算法
等感性趣欢迎关注我的个人公众号交流:bigsai