简而言之,我正在测试一个谷歌驱动表格,它将记录学校选举的投票,以确保它是安全的。
有没有办法从共享 URL 和列表/输入数据打开表单?简而言之,我可以编写一个脚本来表现得像一个会投票并试图使表单崩溃的机器人吗?
简而言之,我正在测试一个谷歌驱动表格,它将记录学校选举的投票,以确保它是安全的。
有没有办法从共享 URL 和列表/输入数据打开表单?简而言之,我可以编写一个脚本来表现得像一个会投票并试图使表单崩溃的机器人吗?
编辑:大约在 2014 年底的某个时候,谷歌表单服务的变化使这个黑客无效。看看是否可以使用谷歌电子表格中的数据“预填”谷歌表单?以及如何预先填写 Google 表单复选框?对于依赖于 Form 方法的解决方案。
Google 表单在显示为“实时表单”时只是一个 HTML 表单,具有表单的所有常规行为。您可以查看实时表单的 HTML 源代码,并获取有助于模拟 POST 请求的信息。
例如,查看电子表格电子邮件触发器中的表单。这是 HTML 表单,为了便于阅读而进行了清理:
<form action="https://docs.google.com/spreadsheet/formResponse?formkey=#FORMKEY#&ifq"
method="POST" id="ss-form">
<br>
<label class="ss-q-title" for="entry_0">First Name
<span class="ss-required-asterisk">*</span>
</label>
<label class="ss-q-help" for="entry_0"></label>
<input type="text" name="entry.0.single" value="" class="ss-q-short" id="entry_0">
<br>
<label class="ss-q-title" for="entry_1">No of User
<span class="ss-required-asterisk">*</span>
</label>
<label class="ss-q-help" for="entry_1"></label>
<select name="entry.1.single" id="entry_1">
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
<br>
<label class="ss-q-title" for="entry_2">Email ID
<span class="ss-required-asterisk">*</span>
</label>
<label class="ss-q-help" for="entry_2"></label>
<input type="text" name="entry.2.single" value="" class="ss-q-short" id="entry_2">
<br>
<input type="hidden" name="pageNumber" value="0">
<input type="hidden" name="backupCache" value="">
<input type="submit" name="submit" value="Submit">
<div class="password-warning">Never submit passwords through Google Forms.</div>
</form>
此屏幕截图中标记了重要元素:
有了动作 URL 和字段名称,我们可以编写一个函数来以编程方式提交表单,方法是修改UrlFetch 文档中的示例:
// Simulate POST to form
function sendHttpPost() {
// Copy the entire URL from <form action>
var formAction = "https://docs.google.com/spreadsheet/formResponse?formkey=#FORMKEY#&ifq";
var payload = {
"entry.0.single": "Nelson", // First Name
"entry.1.single": "10", // No of users
"entry.2.single": "user@example.com" // Email ID
};
// Because payload is a JavaScript object, it will be interpreted as
// an HTML form. (We do not need to specify contentType; it will
// automatically default to either 'application/x-www-form-urlencoded'
// or 'multipart/form-data')
var options = {
"method": "post",
"payload": payload
};
var response = UrlFetchApp.fetch(formAction, options);
}
这是上述脚本的结果,表单响应已添加到电子表格中。