py实现登陆人人网(无验证码)

本脚本通过Python实现人人网自动登录及状态发布功能。使用sgmllib解析HTML,并借助urllib2、cookielib等库处理HTTP请求与Cookies。用户需输入账号密码及待发布状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/python
#-*- coding:UTF-8 -*-
from sgmllib import SGMLParser 
import sys,urllib2,urllib,cookielib 
import datetime 
import time 
class spider(SGMLParser): 
    def __init__(self,email,password): 
        SGMLParser.__init__(self) 
        self.h3=False 
        self.h3_is_ready=False 
        self.div=False 
        self.h3_and_div=False 
        self.a=False 
        self.depth=0 
        self.names="" 
        self.dic={}   
          
        self.email=email 
        self.password=password 
        self.domain='renren.com' 
        try: 
            cookie=cookielib.CookieJar() 
            cookieProc=urllib2.HTTPCookieProcessor(cookie) 
        except: 
            raise 
        else: 
            opener=urllib2.build_opener(cookieProc) 
            urllib2.install_opener(opener)       

    def login(self):
        print '开始登录'
        url='http://www.renren.com/PLogin.do' 
        postdata={ 
                  'email':self.email, 
                  'password':self.password, 
                  'domain':self.domain  
                  } 
        req=urllib2.Request( 
                            url, 
                            urllib.urlencode(postdata)            
                            ) 
         
        self.file=urllib2.urlopen(req).read() 
        idPos = self.file.index("'id':'") 
        self.id=self.file[idPos+6:idPos+15] 
        tokPos=self.file.index("get_check:'") 
        self.tok=self.file[tokPos+11:tokPos+21] 
        rtkPos=self.file.index("get_check_x:'") 
        self.rtk=self.file[rtkPos+13:rtkPos+21] 
     
 
 
    def publish(self,content): 
        url1='http://shell.renren.com/'+self.id+'/status' 
        postdata={ 
                  'content':content, 
                  'hostid':self.id, 
                  'requestToken':self.tok, 
                  '_rtk':self.rtk, 
                  'channel':'renren', 
                  } 
        req1=urllib2.Request( 
                            url1, 
                            urllib.urlencode(postdata)            
                            ) 
        self.file1=urllib2.urlopen(req1).read() 
        print '%s:\n刚才使用你的人人账号 %s 发了一条状态\n内容为:(%s)'%(datetime.datetime.now(),self.email,postdata.get('content','')) 
 
 
 
renrenspider=spider('账户','密码') 
renrenspider.login()
content=raw_input('输入状态信息') 
renrenspider.publish(content)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值