形成数据以从 urlencode 获取特定输出

问题描述 投票:0回答:1

字典 form_data 应该是什么

Python 代码所需的输出 >> data = parse.urlencode(form_data).encode():

“entry.330812148_sentinel=&entry.330812148=Test1&entry.330812148=Test2&entry.330812148=Test3&entry.330812148=Test4”

我尝试了各种字典结构,包括 None、[] 和字典中的字典,但我无法获得此输出

form_data = {'entry.330812148_sentinel':无, 'entry.330812148':'测试1', 'entry.330812148':'测试2', 'entry.330812148':'测试3', 'entry.330812148':'测试4'}

从urllib导入请求,解析 数据 = parse.urlencode(form_data).encode() print("打印解析的表单数据......")

“entry.330812148_sentinel=&entry.330812148=Test1&entry.330812148=Test2&entry.330812148=Test3&entry.330812148=Test4”

python google-forms urlencode
1个回答
0
投票

您可以使用 urllib.parse 中的 parse_qs 返回 python 数据结构

import urllib.parse
>>> s = 'entry.330812148_sentinel=&entry.330812148=Test1&entry.330812148=Test2&entry.330812148=Test3&entry.330812148=Test4'

>>> d1 = urllib.parse.parse_qs(s)
>>> d1
   {b'entry.330812148': [b'Test1', b'Test2', b'Test3', b'Test4']}
© www.soinside.com 2019 - 2024. All rights reserved.