代码简陋,没有技术,需要txt简介才能使用。但是,没有发送概要文件。如果仔细看代码,很容易猜到。希望大家不要拿去擦。因为真的很无趣。
代码所需的相关python模块方法包括urllib、urllib2、cookie lib、hashlib、threading、re、OS、time和random。真的需要很多方法。
#-*-代码: utf-8-*-
Importurllib、urllib2、cookie lib、散列lib、threading
Import re、os、time、random
Import sys
Reload(sys)
(' utf8 ')
Def log(s):
S='\n' str(s)
F=open('log.txt ',' a ')
F.write(s)
F.close()
(s)
()
Class WeiboCn:
All=(“蛇网python学习平台~ ~ ~ ~”“果断关注~”“不知道你有没有发现还有一个你的粉丝。“哈哈!”)。
URL=';
标头={
用户代理“:”Mozilla(windows nt 5.1;RV :2 . 0 . 1)gecko/2010 01 01 Firefox;而且,
}
Def _ _ init _ _ (self,username,password,keyword=none,* args) :
=username
=keyword
=args or
=cookielib。LWPCookieJar()
=urllib2.build_opener())
Urllib2.install_opener()
(username、password)
Def try login (self、username、password) :
Bodies=dict(_=in()),callback=';client=')',entry=' miniblog ',user=' jiangjia @ 1616.net ')
Print“登录前,导入servertime nonce参数(用于加密密码生成)”
preloadurl=';Urllib.urlencode(bodies)
Content=(preloadurl)[1]。read()
Bodies=eval('\{ .*?\} ',内容)[0])
Password=((password))。hexdigest()。hex digest()str(bodies[' servertime '])bodies
加密“Print”将获取密码“% s”% password
Bodies.update (dict (client=')',encoding=' utf-8 ',entry=' miniblog ',gateway=seetFramelogin=1callback=,username=username,useticket=1))
response=(' http://log in . Sina . com.cn/SSO/log in . PHP?Client=)',bodies)[1]
内容=re()
more URL=re . find all(' replace \([\ ' | '](.*?)[\' |'] \ ',内容)
If len(moreurl)==0: print '登录失败!'
Content=(more URL [0],dict(referer=' http://log in . Sina . com.cn/SSO/logi)
n.php?client=)',Host='weibo.com'))[1].read()if username in content:
print "登录成功!"
()
def afterLogin(self):
content = (';)[1].read()
= re.findall('\$uid.*?"(\d+)"', content)[0]
def care(self):
url = 'http://weibo.com/pub/news?source=toptray'
if :
url = 'http://weibo.com/k/%s?Refer=Index_header' % urllib.quote())
log(url)
content = (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=,refer_sort='profile',atnId='profile')
result = ('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("<%s>关注<%d>成功!" % (,ownerUid))
content = [random.randint(0, len()-1)]
bodies = dict(content=content,uid=,ownerUid=ownerUid,productId=productId,productName=productName,resourceId=resourceId,resTitle=resTitle,resInfo=resInfo,some=some,listInDiv=listInDiv,forward=forward,some2=some2)
result = ('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("<%s>评论<%d>成功!<%s>" % (,ownerUid, content))
else:
log("<%s>评论<%d>失败!" % (,ownerUid))
(30, 4 * 60))
else:
log("<%s>关注<%d>失败!" % (,ownerUid))
raise Exception,"关注<%d>失败!" % ownerUid
def unCare(self):
content = ('http://weibo.com/%s/follow' % str())[1].read()
pages = re.findall('<em>(\d+)<\/em>', 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)
c
1fff
ontent = ('http://weibo.com/attention/att_list.php?action=0&tag=&page=%d' % i)[1].read()
cancel = re.findall('粉丝<strong>(.*?)</strong>.*?followcancel\(\'(\d+)', content, re.S)
headers = {'Content-Type':'application/x-www-form-urlencoded', 'Origin':';,'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 = (url, dict(touid=id,fromuid=),headers)[1].read()
if 'A00006' in result:
log("取消关注%s成功!" % id)
else:
log("取消关注%s失败!" % id)
(10)
def _request(self, url, bodies = {}, headers = {}):
request = urllib2.Request(url, urllib.urlencode(bodies), headers = headers)
return (request, .open(request))
def _readMainPage(self):
return )[1].read()
class timer):
def __init__(self, weibo):
(self)
def run(self):
#log (">>>>>>当前用户<%s>线程<%s>" % (.user,self.getName()))
#t = in('%H'))
#looptime = 6 * 6 if t < 22 and t > 8 else 60 * 60 * 5
'''
try:
.care()
log ("当前用户<%s>线程<%s>关注完一页, 休息%d小时,稍后继续~~" % (.user,self.getName(), looptime/3600))
except Exception, e:
log(str(e))
log ("当前用户<%s>线程<%s>出现异常,可能是关注超过上限, 休息%d小时,稍后继续尝试~~" % (.user,self.getName(), looptime/3600))
'''
.unCare()
#(looptime)
#()
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.spli())
u(line)
allWeibo = [apply(WeiboCn,u) for u in userlist]
pound = []
for w in allWeibo:
w = timer(w)
w.setDaemon(True)
w.start()
(w)
#(10)
for x in pound:
x.join()
if __name__ == '__main__':
run(__file__), 'u;))
'''
while True:
m.runtimes += 1
m.run()
'''
1.《【刷微博粉丝】每天学一点。简单的python刷新浪微博粉丝小程序(包括源代码)》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《【刷微博粉丝】每天学一点。简单的python刷新浪微博粉丝小程序(包括源代码)》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/gl/2529932.html