本文實例講述了python使用urllib2提交http post請求的方法。分享給大家供大家參考。具體實現方法如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/usr/bin/python #coding=utf-8 import urllib import urllib2 def post(url, data): req = urllib2.Request(url) data = urllib.urlencode(data) #enable cookie opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) response = opener.open(req, data) return response.read() def main(): posturl = "http://yourwebname/member/login" data = {'email':'myemail', 'password':'mypass', 'autologin':'1', 'submit':'登 錄', 'type':''} print post(posturl, data) if __name__ == '__main__': main()希望本文所述對大家的Python程序設計有所幫助。