Reputation: 43
This is the URL to my google form: https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
And here is the Python code that I have:
import requests
url = "https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/formResponse"
s = requests.Session()
datos = {"entry.1155905730":"TRES", "entry.2110183202":"DOS", "fvv":1, 'draftResponse':[],'pageHistory':0}
x = s.post(url, data=datos)
I get empty responses in my google form, as if all the answers were blank.
What am I missing?
Upvotes: 1
Views: 1387
Reputation: 704
You need to send a post to get into the form before start filling, this is how you see the link you posted: https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
Try to use the DevTools inspector to try to reproduce the requests and responses, inspecting the 'Next' button and in the Network tab you could find the request that gets you into the form:
How to reproduce them with python? A cool site to transform the curl requests in python code curl.trillworks
Paste the request and send it!
In [1]: import requests
...:
...: headers = {
...: 'authority': 'docs.google.com',
...: 'cache-control': 'max-age=0',
...: 'origin': 'https://docs.google.com',
...: 'upgrade-insecure-requests': '1',
...: 'content-type': 'application/x-www-form-urlencoded',
...: 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like
...: Gecko) Chrome/79.0.3945.117 Safari/537.36',
...: 'sec-fetch-user': '?1',
...: 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.
...: 8,application/signed-exchange;v=b3;q=0.9',
...: 'x-chrome-connected': 'id=102279514883169871637,mode=0,enable_account_consistency=false,consist
...: ency_enabled_by_default=false',
...: 'x-client-data': 'CJW2yQEIpbbJAQjEtskBCKmdygEI6qzKAQicrcoBCMuuygEIvbDKAQiOssoBCPe0ygEIl7XKAQiYt
...: coBCOy1ygEI4bbKARirpMoB',
...: 'sec-fetch-site': 'same-origin',
...: 'sec-fetch-mode': 'navigate',
...: }
...:
...: data = {
...: 'fvv': '1',
...: 'draftResponse': '[null,null,"4300515041069574030"]\r\n',
...: 'pageHistory': '0',
...: 'fbzx': '4300515041069574030',
...: 'continue': '1'
...: }
...:
...: response = requests.post('https://docs.google.com/forms/u/0/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ
...: _8WaQESydWrXOsJvz2rRw/formResponse', headers=headers, data=data)
...:
In [2]: 'DOS' in response.text # And boom!
Out[2]: True
Upvotes: 2