Best way to submit data to a form using Python?

I did not work with web programming or web forms before I got lost here. There is a simple perl / cgi

<form method="post" action="/gestalt/cgi-pub/Kaviar.pl" enctype="multipart/form-data">

Now I tried to find questions here, did a google search and read some about urllib2 etc. I think I don’t know enough about this to pick up where all those who left or integrated and used their examples in a meaningful way to solve my problem came from. Here is the page http://db.systemsbiology.net/gestalt/cgi-pub/Kaviar.pl and I want to use this page through python, send the data and extract it and parse it in my script. Sample data is as follows

chr1:4793
chr1:53534
chr1:53560

So the question is, can you help me how to send the data and get the results back to the python script, step by step, or can you guide me to a simple step-by-step guide that teaches how to do this? Thanks

+3
source share
1 answer

This should be a good start:

import urllib, urllib2
url = 'http://db.systemsbiology.net/gestalt/cgi-pub/Kaviar.pl'
form_data = {'chr':'chr1', 'pos':'46743'} # the form takes 2 parameters: 'chr', and 'pos'
                                          # the values given in the dict are
                                          # just examples.
# the next line POSTs the form to url, and reads the resulting response (HTML
# in this case) into the variable response
response = urllib2.urlopen(url,urllib.urlencode(form_data)).read()
# now you can happily parse response.
+4
source

Source: https://habr.com/ru/post/1769423/


All Articles