Javascript 如何使用JS使用随机应答自动填充Google表单
我想用JS随机填写100张谷歌表格。有什么办法吗? 有。Javascript 如何使用JS使用随机应答自动填充Google表单,javascript,forms,google-forms,autofill,Javascript,Forms,Google Forms,Autofill,我想用JS随机填写100张谷歌表格。有什么办法吗? 有。 我在stackoverflow或web上找不到任何东西,只有python或java解决方案。当然,如果可能的话,我想用javascript来实现它。这里有一个脏的脚本,这可能是一个起点。它仅适用于作为示例提供的特定表单。它使用document.querySelector以表单元素为目标 一旦你打开表格,它就会填写,提交,返回,提交,一遍又一遍 要使用它: 在Google Chrome中安装扩展 单击浏览器中出现的图标,选择“Dashbo
我在stackoverflow或web上找不到任何东西,只有python或java解决方案。当然,如果可能的话,我想用javascript来实现它。这里有一个脏的脚本,这可能是一个起点。它仅适用于作为示例提供的特定表单。它使用
document.querySelector
以表单元素为目标
一旦你打开表格,它就会填写,提交,返回,提交,一遍又一遍
要使用它:
- 在Google Chrome中安装扩展
- 单击浏览器中出现的图标,选择“Dashboard”
- 创建一个新脚本,并用下面的代码替换所有内容
- 按Ctrl+S键保存
- 在选项卡中打开表单,并观看它完成工作
/==UserScript==
//@name GoogleForm垃圾邮件发送者
//@名称空间http://tampermonkey.net/
//@version 0.1
//@description垃圾邮件谷歌表单
//@author You
//@匹配https://docs.google.com/forms/*
//@grant none
//==/UserScript==
var formUrl=https://docs.google.com/forms/d/e/1FAIpQLSdQ9iT7isDU8IIbyg-wowB-9HGzyq-xu2NyzsOeG0j8fhytmA/viewform';
var formSchema=[
{type:'radio'},//A
{type:'radio'},//B
{type:'checkbox'},//C
{type:'checkbox'},//D
{type:'short_text',func:generateAnswerE},//E
{type:'段落',func:generateParagraph},//F
];
函数generateAnswerE(){
//假设我们想要一个随机数
返回Math.floor(Math.random()*30)+16;
}
函数generateParagraph(){
//举个例子
返回“你好世界”;
}
(功能(){
addEventListener('load',function()){
if(window.location.pathname.indexOf('/forms/d')==0){//如果我们在表单页面上
submitRandomForm();
}else if(window.location.pathname.indexOf('/forms/u')==0){//如果我们在“提交”页面上
window.location.href=formUrl;
}
函数submitRandomForm(){
var formItems=document.queryselectoral('.freebirdformviewerviewitemsitemsitem');
for(var i=0;i
您可以使用类似或的浏览器扩展在页面上自动运行您的脚本。然后,您只需要编写一个脚本来填充表单,提交表单,然后一遍又一遍地这样做。但是也许谷歌会阻止你,因为你不是人类,而且还在发垃圾邮件,这是真的great@blex但是我怎么能做到呢,谷歌在任何领域都没有任何id,我只有jscontroller,它看起来像某种id,但它是真的id吗?我不知道当我没有任何ID时如何调用getDocumentById。另一个问题是,当我有一个以上的无线字段或一个以上的输入时,我如何选择哪个是什么。因为我只能通过id或标记引用,但是有很多div。老实说,这里只有div,除此之外,您当然不能在这里使用getElementById
。但是querySelector
将帮助您。我成功地编写了一个脏脚本来填充您作为示例提供的表单(您可能会看到一些答案)。我会试着把它清理干净,然后写一封信answer@blex是的,我看得出来,你做了40件衣服。如果你能给我一个脏脚本的话:我的表单比这个复杂,但我想当我看到它是如何工作的时候,我可以用你的模板自己写一些类似的东西。它工作得很好,现在我必须把它扩展到更大的表单,在那里我有很多收音机和复选框等等,这应该很容易,对吧?用肮脏的方式做这件事很容易。不过,让它更易于维护/编辑,以便使用任何表单都会很好。给它一个try@svennnx3我添加了第二个示例,它更容易适应任何形式(不过它只支持某些字段类型,因为我还不能让它使用下拉列表)
// ==UserScript==
// @name GoogleForm Spammer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Spam a Google Form
// @author You
// @match https://docs.google.com/forms/*
// @grant unsafeWindow
// ==/UserScript==
(function() {
window.addEventListener('load', function() {
if (window.location.pathname.indexOf('/forms/d') === 0) { // If we're on the form page
submitRandomForm();
} else if (window.location.pathname.indexOf('/forms/u') === 0) { // If we're on the "submitted" page
goBackToForm();
}
function submitRandomForm() {
// Size
var radios = document.querySelectorAll(".appsMaterialWizToggleRadiogroupRadioButtonContainer"),
radioIndex = Math.floor(Math.random() * radios.length);
radios[radioIndex].click();
// Print
var checkboxes = document.querySelectorAll(".appsMaterialWizTogglePapercheckboxCheckbox"),
checkboxIndex = Math.floor(Math.random() * checkboxes.length);
checkboxes[checkboxIndex].click();
// Age (between 16 and 45)
var age = Math.floor(Math.random() * 30) + 16;
document.querySelector(".quantumWizTextinputPaperinputInput").value = age;
// Submit
document.querySelector(".freebirdFormviewerViewCenteredContent .appsMaterialWizButtonPaperbuttonLabel").click();
}
function goBackToForm() {
window.location.href = 'https://docs.google.com/forms/d/e/1FAIpQLSd7GueJGytOiQpkhQzo_dCU0oWwbk3L1htKblBO1m14VHSpHw/viewform';
}
});
})();
// ==UserScript==
// @name GoogleForm Spammer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Spam a Google Form
// @author You
// @match https://docs.google.com/forms/*
// @grant none
// ==/UserScript==
var formUrl = 'https://docs.google.com/forms/d/e/1FAIpQLSdQ9iT7isDU8IIbyg-wowB-9HGzyq-xu2NyzsOeG0j8fhytmA/viewform';
var formSchema = [
{type: 'radio'}, // A
{type: 'radio'}, // B
{type: 'checkbox'}, // C
{type: 'checkbox'}, // D
{type: 'short_text', func: generateAnswerE }, // E
{type: 'paragraph', func: generateParagraph }, // F
];
function generateAnswerE() {
// Let's say we want a random number
return Math.floor(Math.random() * 30) + 16;
}
function generateParagraph() {
// Just for the example
return "Hello world";
}
(function() {
window.addEventListener('load', function() {
if (window.location.pathname.indexOf('/forms/d') === 0) { // If we're on the form page
submitRandomForm();
} else if (window.location.pathname.indexOf('/forms/u') === 0) { // If we're on the "submitted" page
window.location.href = formUrl;
}
function submitRandomForm() {
var formItems = document.querySelectorAll('.freebirdFormviewerViewItemsItemItem');
for (var i = 0; i < formSchema.length; i++) {
var field = formSchema[i],
item = formItems[i];
switch(field.type) {
case 'radio':
var radios = item.querySelectorAll(".appsMaterialWizToggleRadiogroupRadioButtonContainer"),
radioIndex = Math.floor(Math.random() * radios.length);
radios[radioIndex].click();
break;
case 'checkbox':
var checkboxes = item.querySelectorAll(".appsMaterialWizTogglePapercheckboxCheckbox"),
checkboxIndex = Math.floor(Math.random() * checkboxes.length);
checkboxes[checkboxIndex].click();
break;
case 'short_text':
item.querySelector(".quantumWizTextinputPaperinputInput").value = field.func();
break;
case 'paragraph':
item.querySelector(".quantumWizTextinputPapertextareaInput").value = field.func();
break;
}
}
// Submit
document.querySelector(".freebirdFormviewerViewCenteredContent .appsMaterialWizButtonPaperbuttonLabel").click();
}
});
})();