Post 到 google 表单使用 Python 问题
Post to google form using Python issue
这是我的 google 表格的 URL:
https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
这是我的 Python 代码:
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)
我在 google 表格中收到空的回复,好像所有的答案都是空白。
我错过了什么?
您需要在开始填写之前发送 post 进入表格,这就是您看到 link 的方式 posted:https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
尝试使用 DevTools 检查器尝试重现请求和响应,检查 'Next' 按钮,在“网络”选项卡中您可以找到使您进入表单的请求:
如何用python复制它们?一个很酷的网站,用于转换 python 代码 curl.trillworks
中的 curl 请求
粘贴请求并发送!
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
这是我的 google 表格的 URL: https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
这是我的 Python 代码:
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)
我在 google 表格中收到空的回复,好像所有的答案都是空白。
我错过了什么?
您需要在开始填写之前发送 post 进入表格,这就是您看到 link 的方式 posted:https://docs.google.com/forms/d/e/1FAIpQLSfhLUFVzPk48c-Mdbc1N1ImVAtsZ_8WaQESydWrXOsJvz2rRw/viewform
尝试使用 DevTools 检查器尝试重现请求和响应,检查 'Next' 按钮,在“网络”选项卡中您可以找到使您进入表单的请求:
如何用python复制它们?一个很酷的网站,用于转换 python 代码 curl.trillworks
中的 curl 请求粘贴请求并发送!
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