Created
November 16, 2013 10:39
-
-
Save siongui/7498693 to your computer and use it in GitHub Desktop.
利用BeautifulSoup解析社交網路人人網好友狀態, From
http://www.oschina.net/code/snippet_1253232_26481
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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