python通过表单的post方法自动用户登陆


def post3():
# for mail.sina.com.cn
    import urllib,urllib2,cookielib
    cj = cookielib.CookieJar()
    url_login = 'http://mail.sina.com.cn/cgi-bin/login.cgi'
    body = (('logintype','login'), ('u','*****'), ('psw', '******'))
    opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Opera/9.23')]
    urllib2.install_opener(opener)
    req=urllib2.Request(url_login,urllib.urlencode(body))
    u=urllib2.urlopen(req)
    print u.read().decode('utf-8').encode('gbk')