0

I am trying to submit a HTML form without launching a browser.

here is the code.

import requests
r = requests.get('https://www.isi.uu.nl/Research/Databases/DRIVE/download.php')
r.content.decode('UTF-8')

which gets me a bunch of HTML, which contains a link

<form enctype="multipart/form-data" action="process_download.php" method="post">\r\n    <P>Please enter your e-mail address: <input type="text" name="usermail"/><input type="submit" value="Send mail" /></P>\r\n</form>

is there a way to fill in the content and submit this form without launching a browser in Python?

the whole process of the program would be,

  1. set request to an URL.
  2. keep the session
  3. fill in some content and submit the form automatically without launching a browser.
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

Submitting a form is just an HTTP POST request. So you can create a post request where the body of the request is usermail=username@example.com and the content-type is application/x-www-form-urlencoded

This is equivalent to submitting a form from a browser. If there are multiple values to submit in the form then they are delimited with & just like the query parameters of a GET request.

maschaub
  • 752
  • 4
  • 10