之前有个哥们老是要。就放出来。没啥含量。还有个txt的配置文件才可以用。但是配置文件不发出来了。自己看代码很容易猜得到。。随便扫两眼就算了,不要拿去刷了。因为实在是没意思。也很低级。

1.[代码][Python]代码

# -*- coding: utf-8 -*-

import urllib, urllib2, cookielib, hashlib,threading

import re, os, time, random

import sys

reload(sys)

sys.setdefaultencoding('utf8')

def log(s):

s = "\n" + str(s)

f = open('log.txt', 'a+')

f.write(s)

f.close()

sys.stdout.write(s)

sys.stdout.flush()

class WeiboCn:

all = ('关注你啦~~~~','果断关注~','不知道你有没有发现你的粉丝多了一个?,哈哈!')

url = 'http://www.weibo.com'

header = {

'User-Agent' : 'Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1',

}

def __init__(self, username, password, keyword = None, *args):

self.user = username

self.keyword = keyword

self.all = args or self.all

self.cj = cookielib.LWPCookieJar()

self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))

urllib2.install_opener(self.opener)

self.tryLogin(username, password)

def tryLogin(self, username, password):

bodies = dict(_=int(time.time()),callback='sinaSSOController.preloginCallBack',client='ssologin.js(v1.3.12)',entry='miniblog',user='jiangjia@1616.net')

print "预登录,获取servertime & nonce参数(用来加密生成密码)"

preloadurl = 'http://login.sina.com.cn/sso/prelogin.php?' + urllib.urlencode(bodies)

content = self._request(preloadurl)[1].read()

bodies = eval(re.findall('\{.*?\}',content)[0])

password = hashlib.sha1(hashlib.sha1(hashlib.sha1(password).hexdigest()).hexdigest() + str(bodies['servertime']) + bodies['nonce']).hexdigest()

print "加密获得密码" % password

bodies.update(dict(client='ssologin.js(v1.3.12)',encoding='utf-8',entry='miniblog',gateway='1',password=password,pwencode='wsse',returntype='META',savestate='7',service='miniblog',ssosimplelogin='1',url='http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',username=username,useticket=1))

response = self._request('http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.12)', bodies)[1]

content = response.read()

moreurl = re.findall('replace\([\'|"](.*?)[\'|"]\)', content)

if len(moreurl) == 0: print "登录失败!"

content = self._request(moreurl[0], dict(Referer='http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.12)',Host='weibo.com'))[1].read()

if username in content:

print "登录成功!"

self.afterLogin()

def afterLogin(self):

content = self._request('http://weibo.com')[1].read()

self.uid = re.findall('\$uid.*?"(\d+)"', content)[0]

def care(self):

url = 'http://weibo.com/pub/news?source=toptray'

if self.keyword:

url = 'http://weibo.com/k/%s?Refer=Index_header' % urllib.quote(urllib.quote(self.keyword))

log(url)

content = self._request(url)[1].read()

match = re.findall('loadCommentByRid\((.*?)\)', content)

for x in match:

ownerUid,productId,productName,resourceId,resTitle,resInfo,some,listInDiv,forward,some2 = eval("(%s)" % x)

bodies = dict(uid=ownerUid,fromuid=self.uid,refer_sort='profile',atnId='profile')

result = self._request('http://weibo.com/attention/aj_addfollow.php?refer_sort=profile&atnId=profile&rnd=%f' % random.random(), bodies, dict(Referer = 'http://weibo.com/'))[1].read()

if 'A00006' in result:

log("关注成功!" % (self.user,ownerUid))

content = self.all[random.randint(0, len(self.all)-1)]

bodies = dict(content=content,uid=self.uid,ownerUid=ownerUid,productId=productId,productName=productName,resourceId=resourceId,resTitle=resTitle,resInfo=resInfo,some=some,listInDiv=listInDiv,forward=forward,some2=some2)

result = self._request('http://weibo.com/comment/addcomment.php?f=1&rnd=%f' % random.random(), bodies, dict(Referer='http://weibo.com/pub/news?source=toptray'))[1].read()

if 'A00006' in result:

log("评论成功!" % (self.user,ownerUid, content))

else:

log("评论失败!" % (self.user,ownerUid))

time.sleep(random.randint(30, 4 * 60))

else:

log("关注失败!" % (self.user,ownerUid))

raise Exception,"关注失败!" % ownerUid

def unCare(self):

content = self._request('http://weibo.com/%s/follow' % str(self.uid))[1].read()

pages = re.findall('(\d+)', content)

log(pages)

if len(pages) == 0:

return

p = apply(max,[int(i) for i in pages])

for i in range(p,0,-1):

log(i)

content = self._request('http://weibo.com/attention/att_list.php?action=0&tag=&page=%d' % i)[1].read()

cancel = re.findall('粉丝(.*?).*?followcancel\(\'(\d+)', content, re.S)

headers = {'Content-Type':'application/x-www-form-urlencoded', 'Origin':'http://weibo.com','Referer':'http://weibo.com/attention/att_list.php?action=0&tag=&page=%d' % i}

url = 'http://weibo.com/attention/aj_delfollow.php?rnd=%f' % random.random()

for fans,id in cancel:

if int(fans) > 2000:

log("取消关注%s失败,原因:粉丝数%s大于2000" % (id, fans))

continue

result = self._request(url, dict(touid=id,fromuid=self.uid),headers)[1].read()

if 'A00006' in result:

log("取消关注%s成功!" % id)

else:

log("取消关注%s失败!" % id)

time.sleep(10)

def _request(self, url, bodies = {}, headers = {}):

request = urllib2.Request(url, urllib.urlencode(bodies), headers = headers)

return (request, self.opener.open(request))

def _readMainPage(self):

return self._request(self.url)[1].read()

class timer(threading.Thread):

def __init__(self, weibo):

threading.Thread.__init__(self)

self.weibo = weibo

def run(self):

#log (">>>>>>当前用户线程" % (self.weibo.user,self.getName()))

#t = int(time.strftime('%H'))

#looptime = 6 * 6 if t < 22 and t > 8 else 60 * 60 * 5

'''

try:

self.weibo.care()

log ("当前用户线程关注完一页, 休息%d小时,稍后继续~~" % (self.weibo.user,self.getName(), looptime/3600))

except Exception, e:

log(str(e))

log ("当前用户线程出现异常,可能是关注超过上限, 休息%d小时,稍后继续尝试~~" % (self.weibo.user,self.getName(), looptime/3600))

'''

self.weibo.unCare()

#time.sleep(looptime)

#self.run()

def run(userinc):

f = open(userinc).readlines()

if len(f) < 1 : log("配置文件为空!")

m = re.compile('\|')

userlist = []

for line in f:

if line.startswith('#'):continue

line = m.split(line.strip())

userlist.append(line)

allWeibo = [apply(WeiboCn,u) for u in userlist]

pound = []

for w in allWeibo:

w = timer(w)

w.setDaemon(True)

w.start()

pound.append(w)

#time.sleep(10)

for x in pound:

x.join()

if __name__ == '__main__':

run(os.path.join(os.path.dirname(__file__), 'user.txt'))

'''

while True:

m.runtimes += 1

m.run()

'''

python刷微博转发_python刷新浪微博粉丝相关推荐

  1. python 爬虫 微博 github_GitHub - peanut-shi/weiboSpider: 新浪微博爬虫,用python爬取新浪微博数据...

    功能 爬取新浪微博信息,并写入csv/txt文件,文件名为目标用户id加".csv"和".txt"的形式,同时还会下载该微博原始图片和微博视频(可选). 本程序 ...

  2. python 爬虫 微博 github_GitHub - bubblesran/weiboSpider: 新浪微博爬虫,用python爬取新浪微博数据...

    功能 爬取新浪微博信息,并写入csv/txt文件,文件名为目标用户id加".csv"和".txt"的形式,同时还会下载该微博原始图片和微博视频(可选). 本程序 ...

  3. python 爬虫 微博 github_GitHub - Joria0414/weiboSpider: 新浪微博爬虫,用python爬取新浪微博数据...

    Weibo Spider 本程序可以连续爬取一个或多个新浪微博用户(如胡歌.迪丽热巴.郭碧婷)的数据,并将结果信息写入文件或数据库.写入信息几乎包括用户微博的所有数据,包括用户信息和微博信息两大类.因 ...

  4. python 1069 微博转发抽奖

    1069 微博转发抽奖 (20 分) 小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一 ...

  5. python刷微博转发_一个简单的python刷新浪微博粉丝小程序

    代码简陋没有什么技术,还有个txt的配置文件才可以用.但是配置文件不发出来了.只要你自己好好看代码很容易猜得到.希望大家不要拿去刷了.因为实在是没意思. 代码中需要用到的相关python模块方法有: ...

  6. python刷微博关注_python获取指定微博用户的关注列表

    发现新浪提供的python SDK中存在问题,导致无法获取用户所有的关注列表,只能获取前20个. 首先,看看SDK中获取关注列表的函数: Statuses/friends 获取用户关注列表及每个关注用 ...

  7. python爬虫微博图片_python爬取微博图片及内容

    import random import urllib.request import json import re import requests import time id=(input(&quo ...

  8. python微信语音转发_Python 微信公众号开发(2)——听得懂语音消息的聊天机器人...

    提要: 这篇文章里我们会写: 1.如何对一个聊天机器人进行抓包分析接口: 2.如何将现成的聊天机器 API 部署到自己的公众号上: 3.如何实现接收语音消息并调用聊天机器人 API 自动回复文字: 4 ...

  9. python实现端口转发_Python TCP/IP协议下实现端口转发及重定向菜鸟教程

    对python这个高级语言感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧! 首先,我们用webpy写一个简单的网站,监听8080端口,返回"Hello,EverET ...

最新文章

  1. 不断审视自己,做一个长期主义者
  2. w命令、vmstat命令、top命令、sar命令、noload命令
  3. Ril分析三——客户端请求和响应处理与modem交互
  4. 上白泽慧音(tarjan,图的染色)
  5. 如何在iPhone或iPad的控制中心中控制智能家居设备
  6. 紧跟月影大佬的步伐,一起来学习如何写好JS(上)
  7. qq linux版本下载官网下载,腾讯QQ For Linux
  8. 安卓ListView中CheckBox的使用(支持Item列表项的删除,全选,全不选)
  9. html监控服务器状态,HTML5-WebSocket实现对服务器CPU实时监控
  10. PyCharm中文设置方法(超级简单,一看就会,无需汉化包~)
  11. 二项分布的特征函数及期望与方差 - 随机过程
  12. KEIL MDK中的RO、RW和ZI DATA理解及KEIL中ROM和RAM使用大小计算
  13. flac转换成mp3,flac转mp3方法
  14. vue结合百度地图绘制工具遇到的问题及解决方案(多边形编辑状态下形状显示不全、marker点添加事件无效)
  15. Day66 Web开发7 旅游详情页面
  16. Sequencer: Deep LSTM for Image Classification(LSTM在CV领域杀出一条血路,完美超越Swin与ConvNeXt等前沿算法)
  17. yum下载离线安装包
  18. Zookeeper开源客户端Curator之基本功能讲解
  19. Robotic TMS(二):机器人辅助TMS治疗系统
  20. 视频去水印怎么去-视频去水印哪个软件好用

热门文章

  1. java18_java18
  2. 【github】Support for password authentication was removed on August 13,2021.
  3. 迅雷正式回应搜狐诉讼,揭示网络视频行业潜规则
  4. SQL Server数据库实操 第二波 集合查询、datepart()
  5. 智能家居灯光控制系统
  6. NTSTATUS类型返回值及含义
  7. 【转发】IDM fabless foundry
  8. 联发科和麒麟哪个比较好
  9. AlphaFold2源码解析(4)--模型架构
  10. 霍金:移民太空是避免世界末日最好方式