2010-10-13 140 views
3

我之前沒有使用網絡編程或網絡表單,所以我迷失在這裏。有一個簡單的Perl/CGI使用Python向數據提交數據的最佳方式?

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

現在我試圖在這裏看問題,做了谷歌搜索和閱讀一些有關的urllib2等我想我不夠了解此拿起從那裏所有的留下或整合並以有意義的方式使用他們的例子來解決我的問題。 這裏是頁面 http://db.systemsbiology.net/gestalt/cgi-pub/Kaviar.pl 我想通過python使用這個頁面,提交數據並檢索它並在腳本中解析它。 的樣本數據是這樣的

chr1:4793 
chr1:53534 
chr1:53560 

所以,問題是,你能幫助我,如何一步一步或者你可以請指導我一個簡單的,一步提交數據並得到結果返回到一個python腳本教導如何做到這一點的步驟指南? 感謝

+0

複製所有這些的:http://stackoverflow.com/search?q=%5Bpython%5D+submit+form的 – 2010-10-13 20:57:25

+0

可能重複[以編程方式提交Python中的表單?](http://stackoverflow.com/questions/699238/programmatically-submitting-a-form-in-python) – 2010-10-13 21:00:15

回答

4

這應該是一個良好的開端:

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

它的工作,謝謝。 – biomed 2010-10-13 20:34:14

相關問題