问卷网自动填写提交调查问卷

文章目录

        • 文章导语
        • 实现过程
        • 文章结语

文章导语

此段程序主要使用python的selenium自动化模块,通过网页的自动化来实现题目的自动选择和提交。虽然下面这段代码只针对于某一特定的调查问卷,但是其原理都是一样的,具体情况需要具体分析;问卷调查最主要的还是数据的有效性,此段代码跑出来的数据都是随机的,不能为调查研究提供有效的数据支持,仅仅只是程序本身的学习交流。

实现过程

Author:ZhuHuaRen
Time:01/03/2020

from selenium import webdriver
import random
import time

url = str(input('请输入调查问卷url:'))
t = int(input('请输入提交问卷次数:'))
# 设置提交问卷次数
for times in range(t):
    driver = webdriver.Chrome()
    # 'https://www.wenjuan.com/s/6VVJZfT/'
    driver.get(url)
    # 定位所有的问卷问题
    questions = driver.find_elements_by_css_selector('.matrix')
    for answers in questions:
        # 定位所有问卷问题选项
        answer = answers.find_elements_by_css_selector('.icheckbox_div')
        # 定位需要填写文字的选项,并填入相关内容
        if not answer:
            blank_potion = answers.find_element_by_css_selector('.blank.option')
            blank_potion.send_keys('没有')
            continue
        choose_ans = random.choice(answer)
        choose_ans.click()
    subumit_button = driver.find_element_by_css_selector('#next_button')
    subumit_button.click()
    print('已经成功提交了{}次问卷'.format(int(times)+int(1)))
    # 延迟问卷结果提交时间,以免间隔时间太短而无法提交
    time.sleep(1)
    driver.quit()

问卷网自动填写提交调查问卷_第1张图片

文章结语

针对于实际问题的时候,以上程序还有很多地方需要优化,希望能和大家交流学习。

你可能感兴趣的:(笔记)