开发者

Best way to submit data to a form using Python?

I have not worked with web programming or web forms before so I am lost here. There is a simple perl/cgi

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

Now I tried looking at questions here, did a google search and read some about urllib2 etc. I guess I don't know enough about this to pick up from where all those left or integrate and use their examples in a meaningful way to solve my problem. Here is the page http://db.systemsbiology.net/gestalt/cgi-pub/Kaviar.pl and I want to use this page through python , submitting data and retrieving it and parse it in my script. Sample data is like this

chr1:4793
chr1:53534
chr1开发者_运维问答:53560

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


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜