Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling a google form from R

I would like to use R to fill the following (demo) form:

https://docs.google.com/forms/d/1daaGo7XZaaGGPvTOconG8QZItqaLeIZmSpPPcgxTJvg/viewform

Any suggestions on how this might be done?

Thanks!

like image 267
Tal Galili Avatar asked Oct 17 '25 21:10

Tal Galili


1 Answers

Outline:

Step 1: scrape the FORM element from the web page using standard R web scraping techniques and find the name attribute of all the form widgets you want to fill in. For example:

<input type="radio" name="entry.1945263135" value="Option 1" id="group_1945263135_1" class="ss-q-radio" aria-label="Option 1">

gives you the name of the option 1 radio button from Question 1.

Step 2: get the POST address by scraping the attributes of the FORM element.

Step 3: Use RCurl:postForm to send the form, constructing the .params parameter to map values to widget names. See RCurl docs for that. Exact values for each parameter depends on the widget (checkbox, radio, text, etc) so I won't go into specifics here.

The tricky tricky bit is whether you are trying to make this general for any google form, or if this is a one-shot and you are happy to encode the name attributes into your code. In fact if you only want this to work for one form you can just view the page source and hard-code all the names and POST address into your code with no scraping required. Then its just a matter of constructing the .params for postForm, and if that's the problem then I suggest you read docs, try things, and then ask more specific questions when you fail.

like image 181
Spacedman Avatar answered Oct 19 '25 13:10

Spacedman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!