通过BeautifulSoup来登陆人人网。可以通过info = {'email':'','password':''}进行账号密码的初始化,一个BeautifulSoup的简单应用,过一阶段会写一个关于BeautifulSoup框架使用的小手册,欢迎大家关注啊,求各路读者大大多加指导。
#-*- coding:utf-8 -*-
import urllib
import urllib2
import cookielib
import re
from BeautifulSoup import BeautifulSoup
#获取人人网账号的名称
def getTitle(page):
pattern = re.compile('<title>(.*?)</title>',re.S)
matchResult = re.search(pattern,page)
if matchResult and matchResult.group(1):
return matchResult.group(1)
url = "http://www.renren.com/SysHome.do"
response1 = urllib2.urlopen(url)
source = response1.read()
soup1 = BeautifulSoup(source)
log_url = soup1('form',{'method':'post'})[0]['action']
#info = {'email':'XXXX','password':'XXXX'}
#账号密码必须在运行之前指定
info = {'