Skip to content

Instantly share code, notes, and snippets.

@siongui
Created November 16, 2013 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siongui/7498693 to your computer and use it in GitHub Desktop.
Save siongui/7498693 to your computer and use it in GitHub Desktop.
利用BeautifulSoup解析社交網路人人網好友狀態, From http://www.oschina.net/code/snippet_1253232_26481
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment