当前位置:   article > 正文

自动填写个人信息(问卷星)_问卷星自动填写脚本

问卷星自动填写脚本

1. 问题背景

公司通过问卷星收集个人相关信息,学校通过问卷星开展电影抢票,传统手动输入文字信息已不能满足高效、快速填写问卷的强烈需求。为此,使用预先定义好的程序脚本对问卷进行自动填写,提高信息填写和资源获取效率,已经迫不及待。问卷星信息收集示意图如下:

在这里插入图片描述

2. 自动填写方法

通过 Tampermonkey 结合 JavaScript 完成自动填写问卷脚本,实现脚本的网页监测和自启动。Tampermonkey 界面示意图如下:

在这里插入图片描述

测试完成,并正式投入使用的 JavaScript 脚本如下:

// ==UserScript==
// @name         自动填写个人信息(问卷星)
// @namespace    https://blog.csdn.net/weixin_44392735?spm=1000.2115.3001.5343
// @version      0.1
// @description  本脚本用于个人信息填写和xxxx发布的抢电影票活动。Test Web:https://www.wjx.cn/vm/YHRyoln.aspx
// @author       JasonHu
// @match        https://www.wjx.top/*
// @match        https://www.wjx.cn/*
// @match        https://w.wjx.top/*
// @match        https://w.wjx.cn/*
// @icon         https://cdn4.iconfinder.com/data/icons/marketing-and-digital-marketing/32/business_marketing_advertising_mission-128.png
// @grant        none
// @require      https://code.jquery.com/jquery-3.6.4.min.js
// ==/UserScript==


/*
**info 第一个参数:对应的填入选项(字符串)
**info 第二个参数:匹配的标题(正则表达式),(x|y)查找任何以 | 分隔的选项。
**info 第三个参数:(可选),正则表达式修饰符
*/


//允许在文档完全加载完后执行函数。
$(function(){

    'use strict'; //"use strict" 的目的是指定代码在严格条件下执行,不能使用未声明的变量。

    //数组
    const self_info=[
        ["xxx",/姓名|名字/],
        ["xxxx",/院校/],
        ["200xxxxxxx",/学号|职工号/],
        ["hujs@stu.pku.edu.cn",/邮箱/],
        ["工学院",/学院|院系|单位/],
        ["xxxxx",/班级/],
        ["xxxxx",/专业/],
        ["1587xxxxxxx",/联系方式|电话|手机|手机号/],
        ["1357xxxxx",/QQ|qq/],
        ["xxxxx",/微信/],
        ["无",/其他|其它|备注/],
        ["北京市xxxxx",/收件地址/]
    ];

    //.class 选择器选取带有指定 class 的所有元素。
    const wjx_web={
        module: ".ui-field-contain",    //问题模块class
        title:  ".field-label",         //问题标题class
        text:   ".ui-input-text",       //内容填写class
    };



    //问题数量
    let itemNum = 0;

    //在页面中选取所有包括 ui-field-contain(class) 的元素。(元素选择器)。并对每个元素执行function()函数。
    $(wjx_web.module).each(function(){
        itemNum += 1; //对第 itemNum 个问题进行识别
        let title = $(this).children(wjx_web.title).text(); //text() 返回 field-label(class) 元素内的所有文本内容
        // if (itemNum === 1) {
        //     alert(title);
        // }

        for(let i = 0; i < self_info.length; i++){
            // test() 方法用于 whether a pattern exists in a searched string。
            // 如果 string 中含有匹配的文本,则返回 true,否则返回 false
            if(self_info[i][1].test(title)){
                $("#q"+itemNum).attr("value",self_info[i][0]); //#id 选择器通过 HTML 元素的 id 属性选取指定的元素。
                break;
            }
        }
    });
    //wjx web: submitbtn mainBgColor (20230322)
    //setTimeout($(".submitbtn").click(), 1000); //1秒后将会调用执行click()函数
    //$(".submitbtn").click(); //提交时间太快,wjx出现验证码
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77

3. 测试结果

打开问卷星界面,启动Tampermonkey 脚本,刷新浏览器界面,得到自动填写完个人信息的界面如下:

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/444326
推荐阅读
相关标签
  

闽ICP备14008679号