自动填写或自动化 Google 表单

Has*_*zar 8 google-forms

随着最近预算学校匆忙实施的在家学习动态,我现在面临着一个无意识的机器人般的任务,每天为每个孩子多次填写我的孩子的出勤率。学校分享了这个表格:

在此处输入图片说明 在此处输入图片说明

作为一名开发人员,我想要创建一个用户界面,并让我的孩子在老师要求使用 Zoom 时自己提交这个表单的出勤率。有可能吗?我是 .Net 开发人员,还没有为 Office 365 Online 开发任何东西,也不知道从哪里开始寻找 Google。

hdr*_*drz 10

正如 @AHunt 所写,条目编号曾经位于name表单字段的属性中。截至本回答时间,我无法再name在任何表单字段上找到该属性。script但是,现在标签末尾有一个标签body,带有简短的 javascript 代码,您可以在其中找到条目编号,请参见此处:在此输入图像描述

此外,还可以直接提交带有预填充值的表单。只需将viewformURL 替换为formResponse.

与已接受答案中的 URL 类似,但现在将立即提交。请注意,必须填写所有必填字段!

https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/formResponse?entry.1475351979=Julia&entry.280503419=Andrews&entry.519373518=4&entry.301819105= E&entry.1124370742=艺术


AHu*_*unt 8

可以通过使用预填充值重建表单 URL 来实现。在 Google 表单中,每个问题都在内部以“条目”命名。对于每个问题,您需要找到条目编号并为其分配正确的值并将其添加到 URL 参数中,如下图所示: 在此处输入图片说明 (2021 年 1 月编辑:不再在 HTML 中每个输入字段的名称属性中找到这些 id,如图所示。正如用户 @hdrz 在下面的回答中提到的,这些 id 可以在 Javascript 中找到。 body 标签的结尾。)

我在这里重新创建了您的表单https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform

这是带有预填充值的重建 URL https://docs.google.com/forms/d/e/1FAIpQLSfrGn49hcbeioNNa25Osp4fwTG2xV3BmmN9-cMWWC2-xvcQyg/viewform?entry.1475351979=Julia&entry.4979=Julia&entry.4979=Julia&entry.213015151515151515130151515151515151515151515151515151515151515151515151512018

希望能帮助到你


Tau*_*fat 5

我想我可能会迟到,但还是给你一个解决方案。我制作了类似的脚本来发送我的学校出勤情况。\nGoogle 表单中的每个字段都与一个相关联entry.<id>. 您有两种方法可以自动化表单。

\n

一种方法是提取这些 ID 并制作一个字典,其中entry.<id>键是,你的答案是值。然后你必须发送一个POST使用字典作为数据向表单 URL 发送请求。您已将表格自动化。

\n

要提取 ID,请检查 html 代码并查看<script>页面的(非常)末尾。它 l\xc3\xb2oks 是这样的:

\n
var FB_PUBLIC_LOAD_DATA_ = [null,[null,[[2030831236,"First Name (in English)",null,0,[[1475351979,null,1]\n]\n]\n,[86681139,"Last Name (in English)",null,0,[[280503419,null,1]\n]\n]\n,[836880978,"Grade",null,2,[[519373518,[["KG 1",null,null,null,0]\n,["KG 2",null,null,null,0]\n,["1",null,null,null,0]\n,["2",null,null,null,0]\n,["3",null,null,null,0]\n,["4",null,null,null,0]\n,["5",null,null,null,0]\n,["6",null,null,null,0]\n,["7",null,null,null,0]\n,["8",null,null,null,0]\n,["9",null,null,null,0]\n,["10",null,null,null,0]\n,["11",null,null,null,0]\n,["12",null,null,null,0]\n]\n,1,null,null,null,null,null,0]\n]\n]\n,[221348070,"Section",null,2,[[301819105,[["A",null,null,null,0]\n,["B",null,null,null,0]\n,["C",null,null,null,0]\n,["D",null,null,null,0]\n,["E",null,null,null,0]\n,["G",null,null,null,0]\n]\n,1,null,null,null,null,null,0]\n]\n]\n,[366027193,"Subject",null,2,[[1124370742,[["Math",null,null,null,0]\n,["Science",null,null,null,0]\n,["English",null,null,null,0]\n,["Arabic",null,null,null,0]\n,["Islamic",null,null,null,0]\n,["Social",null,null,null,0]\n,["Moral",null,null,null,0]\n,["Art",null,null,null,0]\n,["Computer",null,null,null,0]\n,["French",null,null,null,0]\n,["Physics",null,null,null,0]\n,["Chemistry",null,null,null,0]\n,["Biology",null,null,null,0]\n,["Business",null,null,null,0]\n]\n,1,null,null,null,null,null,0]\n]\n]\n]\n,null,null,[null,null,null,null,null,[null,null,null,[3,169,244,null,1]\n,[217,242,253,null,1]\n]\n]\n,null,null,null,"Attendance Form",48,null,null,null,null,null,[2]\n]\n
Run Code Online (Sandbox Code Playgroud)\n

正如您所看到的,每个字段都有两个数字。其中一张是身份证,另一张我不知道。第二个数字就是我们需要的ID。使用正则表达式,我们可以提取所有数字并收集列表中的每个第二个数字。该列表将包含所有 ID。

\n

正如其他人所述,另一种方法是使用预填充值重建 URL。但在这种情况下,您也必须提取 ID。

\n

我将它们都包含在一个中并制作了这个脚本:

\n
import requests\nfrom bs4 import BeautifulSoup\nimport re\n\ndef get_questions(url):\n    \n    page = requests.get(url)\n    soup = BeautifulSoup(page.content, \'html.parser\')\n    \n    content = soup.body.find_all(text = re.compile(\'var FB\'))\n    \n    match = re.findall(\'[,]["][\\w\\s]+["][,]\', str(content))\n    #It will match all the questions in the form\n    question_strings = [x.strip(\'"\') for x in match]\n    \n    match_ids = re.findall(\'(?<=\\[\\[)(\\d+)\', str(content))\n    #It will find all the numbers in the content\n    question_ids = [\'entry.\' + x for x in match_ids[1:]]\n    #It will leave the first numbers (they are not the ids)\n    return question_ids\n    \n# Below are only for when you want to know the form fills with their corresponding entry ids\n#    questions = dict(zip(question_strings, question_ids))    \n#    return questions\n\n\ndef send_answers(url, fname, lname, grade, section, subject): #arrange this as per your form requirements\n    \n    ids = get_questions(url)\n    \n    answers = [fname, lname, grade, section, subject]\n    response = dict(zip(ids, answers))\n    \n    if \'viewform\' in url:\n        s = url.index(\'viewform\') \n        response_url = url.replace(url[s::], \'formResponse?\')\n        \n    try:\n        r = requests.post(response_url, response)\n        if r.status_code == 200:\n            return \'[!] Attendence posted !\'\n        #In case an error happens, it will raise an exception\n        else:\n            raise Exception\n\n    #After raising the exception it will retry to submit using url reconstruction with prefilled values\n    except:\n        try:\n            ans_list = [x + \'=\' + y for x, y in zip(ids, answers)]\n            \n            for i in range(0, len(ans_list)):\n                response_url += ans_list[i]\n                response_url += \'&\'\n                \n            response_url.strip("&")    \n            r = requests.get(response_url)\n            status = r.status_code\n            \n            if status == 200:\n                return \'[!] Attendance sent !\'\n            else:\n                raise Exception\n        #If still an error happens, it will print out a message.\n        except:\n            return \'[!] Attendance not sent !\'\n                \n\nurl = \'Form URL here\'\n\nfname = \'Your first name here\'\nlname = \'Your last name here\'\ngrade = \'Your grade here\'\nsection = \'Section here\'\nsubject = \'Enter subject\'\n\nprint(send_answers(url, fname, lname, grade, section, subject))\n
Run Code Online (Sandbox Code Playgroud)\n

希望能帮助到你。对不起,我的英语不好。

\n