• python发人人状态


    python发人人状态

     1 #-*- coding:UTF-8 -*-
     2 '''
     3 ======================================
     4 此程序根据 http://www.oschina.net/code/snippet_148170_10661 内容改编
     5 Adapted BY: bepcao
     6 Mail:peterc9511@gmail.com
     7 ======================================
     8 '''
     9 from sgmllib import SGMLParser
    10 import sys,urllib2,urllib,cookielib
    11 import datetime
    12 import time
    13 class spider(SGMLParser):
    14     def __init__(self,email,password):
    15         SGMLParser.__init__(self)
    16         self.h3=False
    17         self.h3_is_ready=False
    18         self.div=False
    19         self.h3_and_div=False
    20         self.a=False
    21         self.depth=0
    22         self.names=""
    23         self.dic={}   
    24          
    25         self.email=email
    26         self.password=password
    27         self.domain='renren.com'
    28         try:
    29             cookie=cookielib.CookieJar()
    30             cookieProc=urllib2.HTTPCookieProcessor(cookie)
    31         except:
    32             raise
    33         else:
    34             opener=urllib2.build_opener(cookieProc)
    35             urllib2.install_opener(opener)       
    36 
    37     def login(self):
    38         print '开始登录'
    39         url='http://www.renren.com/PLogin.do'
    40         postdata={
    41                   'email':self.email,
    42                   'password':self.password,
    43                   'domain':self.domain  
    44                   }
    45         req=urllib2.Request(
    46                             url,
    47                             urllib.urlencode(postdata)            
    48                             )
    49         
    50         self.file=urllib2.urlopen(req).read()
    51         idPos=self.file.index("'id':'")
    52         self.id=self.file[idPos+6:idPos+15]
    53         tokPos=self.file.index("get_check:'")
    54         self.tok=self.file[tokPos+11:tokPos+21]
    55         rtkPos=self.file.index("get_check_x:'")
    56         self.rtk=self.file[rtkPos+13:rtkPos+21]
    57     
    58 
    59 
    60     def publish(self,content):
    61         url1='http://shell.renren.com/'+self.id+'/status'
    62         postdata={
    63                   'content':content,
    64                   'hostid':self.id,
    65                   'requestToken':self.tok,
    66                   '_rtk':self.rtk,
    67                   'channel':'renren',
    68                   }
    69         req1=urllib2.Request(
    70                             url1,
    71                             urllib.urlencode(postdata)            
    72                             )
    73         self.file1=urllib2.urlopen(req1).read()
    74         print '%s:\n刚才使用你的人人账号 %s 发了一条状态\n内容为:(%s)'% (datetime.datetime.now(),self.email,postdata.get('content',''))
    75 
    76 
    77 
    78 renrenspider=spider('email','password')
    79 renrenspider.login()
    80 content=raw_input('请输入状态的内容:')
    81 renrenspider.publish(content)
  • 相关阅读:
    2017-2018 ACM-ICPC, NEERC, Northern Subregional Contest C
    Codeforces Round #445 div.2 D. Restoration of string 乱搞
    hdu 6228 Tree
    数塔(入门级dp)
    逆序数(归并排序和树状数组)
    poj2104 K-th Number 主席树入门;
    Codeforces Round #466 (Div. 2)F. Machine Learning 离散化+带修改的莫队
    Codeforces Round #470 (rated, Div. 2, based on VK Cup 2018 Round 1)C. Producing Snow+差分标记
    2038: [2009国家集训队]小Z的袜子(hose)+莫队入门
    Codeforces Round #220 (Div. 2)D. Inna and Sequence 树状数组+二分
  • 原文地址:https://www.cnblogs.com/ketmales/p/2893001.html
Copyright © 2020-2023  润新知