- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- __author__= 'anonymous_ch'
- import urllib2
- import urllib
- import cookielib
- from bs4 import BeautifulSoup
- data={"email":"your_email","password":"your_password"}
- post_data=urllib.urlencode(data )
- cj=cookielib.CookieJar()
- opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
- req=urllib2.Request("http://www.renren.com/PLogin.do",post_data)
- content=opener.open(req)
- bs4=BeautifulSoup(content)
- list = bs4.find('div','feed-list').findAll('article')
- for news in list:
- state = []
- for my_tag in news.h3.contents:
- string = my_tag.string
- if string != None:
- state.append(string)
- print ' '.join(state)
- #该片段来自于http://www.codesnippet.cn/detail/261120137481.html
来源: http://www.codesnippet.cn/detail/261120137481.html