#-*- coding:UTF-8 -*- from sgmllib import SGMLParser import sys,urllib2,urllib,cookielib import datetime import time class spider(SGMLParser): def __init__(self,email,password): self.email=email self.password=password self.domain='renren.com' try: cookie=cookielib.CookieJar() cookieProc=urllib2.HTTPCookieProcessor(cookie) except: raise else: opener=urllib2.build_opener(cookieProc) urllib2.install_opener(opener) def login(self): print 'Start Login' url ='http://www.renren.com/PLogin.do' postdata={ 'email':self.email, 'password':self.password, 'domain':self.domain } req = urllib2.Request(url,urllib.urlencode(postdata)) self.file = urllib2.urlopen(req).read() print self.file renrenspider = spider('userName','passWord') renrenspider.login()