如何使用python请求发送有效负载

2024-04-20 01:39:10 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我理解通过请求发送有效负载的概念,但我很难理解如何知道要发送什么。你知道吗

例如,payload = {'key1': 'value1', 'key2': 'value2'}是有效负载, 但是我怎么才能找到钥匙1呢?是元素ID吗?我与selenium密切合作,我正在寻找一种更快的替代方案。你知道吗

谢谢你的帮助,杰克。你知道吗


Tags: id概念元素selenium方案payload钥匙key2
1条回答
网友
1楼 · 发布于 2024-04-20 01:39:10

Requests是一个库,允许您使用GET、POST、PUT等请求获取URL。在其中一些服务器上,您可以添加有效负载,或者服务器用来执行某些操作的额外数据。你知道吗

所以负载由服务器处理,但是您必须提供它们,这是通过定义字典来完成的。这完全取决于服务器期望接收的内容。我假设您阅读了以下解释:

Source

You often want to send some sort of data in the URL’s query string. If you were constructing the URL by hand, this data would be given as key/value pairs in the URL after a question mark, e.g. httpbin.org/get?key=val. Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument. As an example, if you wanted to pass key1=value1 and key2=value2 to httpbin.org/get, you would use the following code:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.get('https://httpbin.org/get', params=payload)

这里的有效负载是一个变量,它定义了请求的参数。你知道吗

相关问题 更多 >