python加cookie访问

阅读更多
import httplib, urllib
def test ():
    a=open("d:\\2.gif","rb").read()
    ck = cookielib.CookieJar()
    url_login = 'http://xxxxyinse.cn/BS/admin/module/user/login.php?step=2&fid=0&path=...
    params = urllib.urlencode({'username':'13800138000',
         'password':'123456',
         'phone_id':'1'})
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(ck))
    opener.addheaders = [('User-Agent','python-urllib/1.15')]
    urllib2.install_opener(opener)
    req = urllib2.Request(url_login,params)
    urllib2.urlopen(req)
    param = urllib.urlencode({'name':'ytjhgjghj',
         'memo':'hgjghjy',
        "face":"",
        'picture[]':(a),
        'Submit2':"发帖"})
    opener.addheaders = [('User-Agent','Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; MAXTHON 2.0)')]
    urllib2.install_opener(opener)
    req = urllib2.Request('http://xxxx/admin/module/bbs/upfiles.php?step=1&fid=7&path=bbs/index....)
    u=urllib2.urlopen(req)
    print u.read() 

你可能感兴趣的:(Python,PHP,BBS,Windows,Phone,Windows)