访问需要cookie的网页的Python程序

xiaonei.com
5q.com

import urllib2,cookielib,urllib,httplib,re
cookie=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
urllib2.install_opener(opener)
str="email=******&password=****&origURL=%2FSysHome.do&submit=%E7%99%BB%E5%BD%95"
rexp=re.compile(r')
frquene=[]
login=urllib2.urlopen("http://www.xiaonei.com/Login.do",str)
res=login.read()
#print res
cond=True
i=0
while cond:
    cond=False
    frlist_url="http://xiaonei.com/myfriendlist.do?curpage=%d&univ=" %(i,)
    print "!!",frlist_url
    i=i+1
    frlist=urllib2.urlopen(frlist_url)
    res=frlist.read()
    print "!!",res
    lines=res.split("\n")
    for line in lines:
        a=rexp.search(line)
        if a:
            cond=True
            frquene.append(a.groups()[0])
            
for fr in frquene:
    print fr