当前位置: 移动技术网 > IT编程>脚本编程>Python > python实现人人自动回复、抢沙发功能

python实现人人自动回复、抢沙发功能

2019年06月16日  | 移动技术网IT编程  | 我要评论

中国创业网,诱夫:囧妃桃花多,死侍1080p

最近人人上看到有好友总是使用软件抢沙发,便决定用python也写一个玩玩

一、状态回复表单post

同样使用chrome开发者工具抓包

红色选择选中部分为必须提交的部分 

提交表单的内容

postdata = { 
    'c': content, #1  你要评论的内容 
    'owner': owner, #2 该状态的所有者id 
    'source': source, #3 该状态的id 
    't': 3, #4  这条不用修改 
    'requesttoken': xxx, #5  上图选中部分 
    '_rtk': 'xxx', #6  上图选中部分 
  } 

二、抢沙发思路

每个20s访问一下人人主页,使用beautifulsoup抓取data-id(对应owner)、data-source(对应source)

模拟表单提交即可完成抢沙发

target_id    集合存放需要抢沙发的好友id(data-id)

reply_id      集合存放已经回复过的状态id(data-source)

通过上述两个集合保证不重复评论,且只评论指定好友的状态

#coding=utf8 
import re 
import urllib 
import urllib2 
import time 
from bs4 import beautifulsoup 
 
__author__ = 'snow' 
cookie = '你自己cookie' 
headers = {'cookie': cookie, 
      'user-agent': 'mozilla/5.0 (macintosh; intel mac os x 10_9_0) applewebkit/537.36 (khtml, like gecko) chrome/31.0.1650.63 safari/537.36' 
} 
target_id = set(['5002986xx']) #存放需要抢沙发的好友id 
reply_id = set() 
 
def load_status(): 
  url = 'http://www.renren.com/' 
  req = urllib2.request(url, headers=headers) 
  page = '' 
  try: 
    page = urllib2.urlopen(req).read() 
  except: 
    print 'urlopen error' 
  soup = beautifulsoup(page) 
  for i in soup.find_all('figure'): 
    # print i.get('data-id') 
    if i.get('data-id') in target_id: 
      owner_id = i.get('data-id') 
      source_id = i.get('data-source') 
      if source_id not in reply_id: 
        auto_reply(owner_id, source_id) 
        print i.get('data-id') + ' ' + source_id 
      else: 
        print 'replyed this status' 
 
def auto_reply(owner, source): 
  url = 'http://status.renren.com/feedcommentreply.do?fin=0&ft=status&ff_id=' + str(owner) 
  content = '(shafa10) ' + time.strftime('于%h时%m分%s秒') + " ~" 
  postdata = { 
    'c': content, #1 
    'owner': owner, #2 
    'source': source, #3 
    't': 3, #4 
    'requesttoken': -7683150xx, #5 自己修改 
    '_rtk': '9df56fxx', #6<span style="white-space:pre;">  </span>自己修改 
  } 
  req = urllib2.request(url, urllib.urlencode(postdata), headers=headers) 
  page = urllib2.urlopen(req).read() 
  reply_id.add(source) 
 
 
while true: 
  load_status() 
  time.sleep(20) 
  print time.strftime('%h:%m:%s') 

效果图

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网