import urllib
import urllib2
name = "name field"
data = {
"name" : name
}
encoded_data = urllib.urlencode(data)
content = urllib2.urlopen("http://www.abc.com/messages.php?action=send",
encoded_data)
print content.readlines()
只需用您的表单提交的网址替换http://www.abc.com/messages.php?action=send
回复您的评论:如果网址是您的表单所在的网址,并且您只需要为一个网站执行此操作,请查看该页面的源代码并找到
并将此地址作为urllib2.urlopen的参数
你必须意识到提交按钮的作用.它只是发送一个Http请求到由表单中的动作定义的url.那么你所做的就是用urllib2模拟这个请求