0

我正在尝试模仿这种网络请求机制。我有所有的数据。我需要知道的是如何使用 Python Selenium 执行 POST 请求?

铬开发

4

1 回答 1

0

我真的只需要从 python 发出一个 post 请求,实际上根本不需要使用 selenium。正如 Tim 已经指出的那样,您希望在 selenium 中模拟用户与网页的交互。

如果你真的只是想发出一个 post 请求,你可以使用http.client

>>> import http.client, urllib.parse
>>> params = urllib.parse.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
...            "Accept": "text/plain"}
>>> conn = http.client.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print(response.status, response.reason)
302 Found
>>> data = response.read()
>>> data
b'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()
于 2021-11-27T07:06:53.417 回答