Google Apps Script script to fetch form data
lang
en
date
Apr 6, 2024
slug
Post-09-en
status
Published
tags
Tech Share
summary
Automatically fetch Paiza emails using a Google Apps Script (GAS).
type
Post
Today the teacher assigned a task to automatically get Paiza emails through GAS (Google Apps Script) script. Actually the task is very simple, but I thought too complicated, resulting in how the problem could not be solved. In the end, it was Chris' off-site assistance that provided a new idea and solved it in one go.
Initiate post request, submit form data
It's that simple.
First use Chrome to hijack the requested data and get the form data we need.

Google Apps Script initiates a POST request to submit the form data, using the UrlFetchApp service.
function submitFormData() { var url = 'URL'; // 目标URL var formData = { key1: 'value1', key2: 'value2', // 添加更多的表单数据 }; var options = { method: 'post', payload: formData }; var response = UrlFetchApp.fetch(url, options); Logger.log(response.getContentText()); }
We first define the destination URL, which contains the form data to be submitted in a
formData
object. Then, we create an options
object, which specifies the method of the request as POST and passes the form data as a payload
to the request. Finally, we use the UrlFetchApp.fetch() method
to initiate the POST request and log the response in the log.