人人网自动登录脚本_python

import urllib,urllib2,cookielib
from BeautifulSoup import BeautifulSoup
myCookie = urllib2.HTTPCookieProcessor(cookielib.CookieJar())
openner = urllib2.build_opener(myCookie)

post_data = {'email':'ChenxofHit@gmail.com',
             'password':'#¥#¥##¥#¥#¥',
             'origURL':'http://www.renren.com/Home.do',
             'domain':'renren.com'}
req = urllib2.Request('http://www.renren.com/PLogin.do', urllib.urlencode(post_data))
html_src = openner.open(req).read()
parser = BeautifulSoup(html_src)

article_list = parser.find('div','feed-list').findAll('article') 
for my_article in article_list: 
    state = [] 
    for my_tag in my_article.h3.contents: 
        factor = my_tag.string 
        if factor != None: 
            factor = factor.replace(u'\xa0','') 
            factor = factor.strip(u'\r\n') 
            factor = factor.strip(u'\n') 
            state.append(factor) 
    print ' '.join(state)
 
在IDLE中运行上述代码:执行结果为:

ph

posted on 2011-03-29 13:51  追求卓越 挑战极限  阅读(1869)  评论(0编辑  收藏  举报

导航