2010-10-13 94 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

相关问题