Python implements renren login example sharing

  • 2020-04-02 13:22:39
  • OfStack


import re
import urllib2
import cookielib
def renren():
    cj = cookielib.LWPCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    email = ''
    pwd   = ''

    # The login ..
    print 'login......'
    url = "http://www.renren.com/PLogin.do"
    postdata = "email="+email+"&password="+pwd+"&origURL=http%3A%2F%2Fwww.renren.com%2FSysHome.do&domain=renren.com"
    req = urllib2.Request(url,postdata)
    res = opener.open(req).read()
    print 'succeed!'

    # Get the current state 
    s = r'(?s)id="currentStatus">.*?<a ui-async="async" title="([^"]*)'
    match = re.search(s, res, re.DOTALL)
    if match:
        result = match.groups(1)
        print 'current status: ', result[0]
renren()


Related articles: