本文实例讲述了python实现自动登录人人网并采集信息的方法。分享给大家供大家参考。具体实现方法如下:
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import re import urllib2 import urllib import cookielib class Renren(object): def __init__(self): self.name = self.pwd = self.content = self.domain = self.origURL = '' self.operate = ''#登录进去的操作对象 self.cj = cookielib.LWPCookieJar() try: self.cj.revert('./renren.coockie') except Exception,e: print e self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) urllib2.install_opener(self.opener) def setinfo(self,username,password,domain,origURL): '''设置用户登录信息''' self.name = username self.pwd = password self.domain = domain self.origURL = origURL def login(self): '''登录人人网''' params = { 'domain':self.domain, 'origURL':self.origURL, 'email':self.name, 'password':self.pwd} print 'login.......' req = urllib2.Request( 'http://www.renren.com/PLogin.do', urllib.urlencode(params) ) self.file=urllib2.urlopen(req).read() newsfeed = open('news.html','w') try: newsfeed.write(self.file) except Exception, e: newsfeed.close() self.operate = self.opener.open(req) print type(self.operate) print self.operate.geturl() if self.operate.geturl(): print 'Logged on successfully!' self.cj.save('./renren.coockie') self.__viewnewinfo() else: print 'Logged on error' def __viewnewinfo(self): '''查看好友的更新状态''' self.__caiinfo() def __caiinfo(self): '''采集信息''' h3patten = re.compile('<article>(.*?)</article>')#匹配范围 apatten = re.compile('<h3.+>(.+)</h3>:')#匹配作者 cpatten = re.compile('</a>(.+)\s')#匹配内容 content = h3patten.findall(self.file) print len(content) infocontent = self.operate.readlines() print type(infocontent) print 'friend newinfo:' for i in infocontent: content = h3patten.findall(i) if len(content) != 0: for m in content: username = apatten.findall(m) info = cpatten.findall(m) if len(username) !=0: print username[0],'说:',info[0] print '----------------------------------------------' else: continue ren = Renren() username = 'username'#你的人人网的帐号 password = 'password'#你的人人网的密码 domain = 'www.renren.com'#人人网的地址 origURL = 'http://www.renren.com/home'#人人网登录以后的地址 ren.setinfo(username,password,domain,origURL) ren.login()
希望本文所述对大家的Python序设计有所帮助。
本文向大家介绍Python实现登录人人网并抓取新鲜事的方法,包括了Python实现登录人人网并抓取新鲜事的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Python实现登录人人网并抓取新鲜事的方法。分享给大家供大家参考。具体如下: 这里演示了Python登录人人网并抓取新鲜事的方法(抓取后的排版不太美观~~) 希望本文所述对大家的Python程序设计有所帮助。
本文向大家介绍python实现自动登录人人网并访问最近来访者实例,包括了python实现自动登录人人网并访问最近来访者实例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了python实现自动登录人人网并访问最近来访者的方法,分享给大家供大家参考。 具体方法如下: 希望本文所述对大家的Python程序设计有所帮助。
本文向大家介绍python人人网登录应用实例,包括了python人人网登录应用实例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了python人人网登录应用的实现方法,分享给大家供大家参考。 具体方法如下: 希望本文所述对大家的Python程序设计有所帮助。
本文向大家介绍SpringBoot 并发登录人数控制的实现方法,包括了SpringBoot 并发登录人数控制的实现方法的使用技巧和注意事项,需要的朋友参考一下 通常系统都会限制同一个账号的登录人数,多人登录要么限制后者登录,要么踢出前者,Spring Security 提供了这样的功能,本文讲解一下在没有使用Security的时候如何手动实现这个功能 demo 技术选型 SpringBoot JW
我的基于节点的Web服务链接到外部第三方网站,该网站需要我们也拥有的用户名/密码(但与我们的Web服务的登录不相同)。为了提供无缝的用户体验,当用户单击到第三方网站的链接时,我希望使用用户名/密码自动登录,并将其直接带到外部页面的仪表板。 至少,我想用这些信息预先填充第三方登录表单,但这篇详细描述类似情况的文章并没有让我感到乐观。 我不相信第三方站点支持OAuth或现有的SSO协议。我不能使用iF
本文向大家介绍python爬虫 模拟登录人人网过程解析,包括了python爬虫 模拟登录人人网过程解析的使用技巧和注意事项,需要的朋友参考一下 requests 提供了一个叫做session类,来实现客户端和服务端的会话保持 使用方法 1.实例化一个session对象 2.让session发送get或者post请求 下面就用人人网来实战一下 就这么简单,模拟登录上人人网并且获取了个人首页信息页面保