Auto-Fill or automate a Google Form

With the recent study-from-home dynamics hastly implemented by budget schools, I am now facing a mindless-robot-like-task of filling in attendance for my kids everyday multiple times per child. The school shared this form: enter image description here enter image description here I, being a developer, want to create a UI and have my kids submit thier attendance to this form on thier own when the teacher asks for one over Zoom. Ids it possible? I'm a .Net developer and have not developed anything for Office 365 Online and have no idea where to start looking for Google.

asked May 17, 2020 at 9:36 DoomerDGR8 DoomerDGR8 5,020 7 7 gold badges 49 49 silver badges 97 97 bronze badges

6 Answers 6

enter image description here

It is possible by reconstructing the form URL with pre-filled values. In the Google Form, each question is named internally with "entry.". For each of the question, you need to find the entry number and assign them the right values and add it to the URL parameters like in the below image: (Edited Oct 2021: The ids are no longer found in the name attribute of each input field in the HTML as shown in the image. They are now located in a div within the form element. @hdrz's answer below to look in the Javascript present just at the end of the body tag is now also defunct.)

17 7 7 bronze badges answered May 19, 2020 at 8:53 31 1 1 gold badge 4 4 silver badges 12 12 bronze badges

Hmmmmmmmmmmmm. I guess I'd still have to scrape the page to get the names to fill but this is very interesting. :)

Commented Nov 24, 2020 at 6:25

OK, I've tried this, but when I scrape my form, those values aren't in the HTML. The name and id attributes are both missing on all form elements. Also, when I view your form, I don't see the values on your form either. But, your prefill URL does work. So the missing thing at the moment is just how to get the values in the first place.

Commented Nov 26, 2020 at 9:00

Regarding this solution, how can someone format the query string to auto fill a date input field of the form DD/MM ? It seems to me it expects two parameters.

Commented Jan 7, 2022 at 13:29

enter image description here

As @AHunt writes, the entry number used to be in a name attribute on the form fields. As of this answer time, I can no longer find the name attribute on any of the form fields. However, now there is a script tag at the end of the body tag, with a short javascript code, and in it you can find the entry numbers, see here:

Also, it is possible to submit the form directly with pre-filled values. Just replace viewform in the URL with formResponse .

Similar URL as in the accepted answer, but now it will be submitted at once. Note that all required fields have to be filled!

answered Sep 15, 2020 at 5:48 461 6 6 silver badges 13 13 bronze badges

I think I may be late but still give you a solution. I had made similar script to send my school attendance. Every field in Google Forms is associated with a entry. . You have two ways to automate the form.

One way is to extract those IDs with and make a dictionary where entry. is the key and your answer is the value.Then you have to send a POST request to the form URL with the dictionary as the data. You have automated the form.

To extract the IDs, inspect the html code and look at the at the (very) end of the page. It lòoks something like this :

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

As you can see there are two numbers with each field. One of them is the ID and another one I don't know. The second number is the ID we need. Using RegEx we can extract all the numbers and collect every second number in a list. This list will contain all the IDs.

Another way, as stated by others, is to reconstruct the URL with prefilled values. But in this too you have to extract the IDs.

I have included both of them in one and made this script :

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

Hope it helps. Sorry for my bad English.