当前位置:天才代写 > tutorial > Python教程 > python通过urllib2提交http post请求

python通过urllib2提交http post请求

2018-05-17 08:00 星期四 所属: Python教程 浏览:356

python通过urllib2提交http post请求

python">#!/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://www.xiami.com/member/login" 
    data = {'email':'myemail', 'password':'mypass', 'autologin':'1', 'submit':'登 录', 'type':''} 
    print post(posturl, data) 

if __name__ == '__main__': 
    main()  

标签:python

 

    关键字:

天才代写-代写联系方式