0

I'm trying to mimic this web requests mechanism. I have all the data. What I need to know is how I can do the POST requests using Python Selenium?

Chrome Dev

Ekky Armandi
  • 106
  • 9
  • 1
    You don't submit POST requests. You fill in the fields as the user would have, then you simulate clicking the "submit" button. The browser will submit the request. You are basically a robot driving Chrome. – Tim Roberts Nov 27 '21 at 06:31
  • I can't find any button. That's why I need the post requests. – Ekky Armandi Nov 27 '21 at 06:33
  • How did you generate the display above? It could be they have another control with an `onClick` event that submits the request. – Tim Roberts Nov 27 '21 at 07:12
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 01 '21 at 18:11

1 Answers1

0

I you really just need to make a post request from python there is actually no need to use selenium at all. As Tim already pointed out you want to simulate the user interaction with the web page in selenium.

If you really just want to make a post request, you can just use 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()
doberkofler
  • 9,511
  • 18
  • 74
  • 126