web表单提交GET和POST方法示例,web表单getpost,需要了解,基于pytho


需要了解,基于python语言的web表单提交方法源码,的朋友可以参考如下代码,这是get和post两种,我这里小小的总结了一下应用而已。

python web表单

简单的web表单提交方式:GET和POST方法源码如下:

#!/usr/bin/env python#--coding = UTF-8--import sys,urllib2,urllibzipcode = sys.argv[1]def GET():    def addGETdata(url,data):    """    Adds data to url.Data should be a list or tuple consisting of    2_item lists or tuples of the form: (key,value).    Item that have no key should have key set to None.    A given key may occur more than once.    """        return url + '?' + urllib.urlencode(data)        url = addGETdata("你的url地址",[("你要访问的网页",zipcode)])    #example:url = addGETdata("http://www.xxxxxx.com/xxx/",(["query",zipcode]))    print "Using URL",url    req = urllib2.Request(url)    fd = urllib2.urlopen(req)    while 1:        data = fd.read(1024)        if not len(data):            break        sys.stdout.write(data)#www.iplaypy.comdef POST():    url = "你的url地址"#example:url = "http://www.xxxxxx.com/xxx/"    data = urllib2.urlencode([("你要访问的网页",zipcode)])    req = urllib2.Request(url)    fd = urllib2.urlopen(req,data)    while 1:        data = fd.read(1024)        if not len(data):            break        sys.stdout.write(data)

相关文章推荐:
1、Python urllib2模块post/get 下载网络资源
2、PycURL如何实现POST方法源码分享
3、Python使用GET方法发送HTTP请求源码

编橙之家文章,

评论关闭