本文實例講述了python通過post提交數(shù)據(jù)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
# -*- 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" #定義要提交的數(shù)據(jù) 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
調(diào)用函數(shù):
希望本文所述對大家的Python程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選