Search code examples
pythonurllibgoogle-forms

Response to a google form including text box?


Here is my example form:
https://docs.google.com/forms/d/e/1FAIpQLSfVXZ1721ZRrHetp1qUak9T-o-MwKA9G3q01rLAFI2OJhZjUw/viewform

I want to send a response to it with python, but I don't know how to fill the "text box", so I can't even start it. Can you help me, please?


Solution

  • For submitting data to google form you first need to replace viewform to formResponse in your url.

    You are going to POST submission to the form response URL. You need to keep 2 things in mind.

    1. Get the form response URL. It can be found by replacing your form ID into the following:

      https://docs.google.com/forms/d/<form_id>/formResponse

    2. Assemble the submission. This will be a dictionary reference with keys being the IDs of the form questions and the values being what you'd like to submit. To get the IDs, again go to your live form and inspect the html (Right Click -> Inspect Elements) components where you would typically input your information. You should discover a group of ss-structure passage objects with name attribute like:

      name="entry.<id>"

    A simple program to send response would be:

    import requests
    url ="https://docs.google.com/forms/d/e/1FAIpQLSfVXZ1721ZRrHetp1qUak9T-o-MwKA9G3q01rLAFI2OJhZjUw/formResponse"
    data_to_send = 'DATA' # Assign Data to be sent
    requests.post(url, {"entry.685250623":data_to_send}) # Found the entry Id viewing your form
    

    Hope this answers your question!!!