本文實例講述了python通過post提交數據的方法。分享給大家供大家參考。具體實現方法如下:
# -*- coding: cp936 -*-import urllib2import urllibdef postHttp(name=None,tel=None,address=None, price=None,num=None,paytype=None, posttype=None,other=None): url="http://www.xxx.com/dog.php" #定義要提交的數據 postdata=dict(name=name,tel=tel,address=address,price=price, num=num,paytype=paytype,posttype=posttype,other=other) #url編碼 postdata=urllib.urlencode(postdata) #enable cookie request = urllib2.Request(url,postdata) response=urllib2.urlopen(request) print response
調用函數:
代碼如下:postHttp('姓名','電話','地址','230元', '1','貨到付款','EMS國內郵政特快專遞','饑渴長耳兔-國際品牌')
希望本文所述對大家的Python程序設計有所幫助。
新聞熱點
疑難解答