- A+
所属分类:python
# -*- coding: utf-8 -* import requests import time #不延时可以去掉 import re import os import sys import string n = 0 #循环次数 a = 9 #计数器 b = 0 tiloun = 88 #中奖楼层 tilouid = 8888 #踢楼帖子ID Read_nowlou = 0 #当前楼层 starttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) nowtime = 0 msg="这里是"#踢楼恢复内容 username = '论坛账户' # 论坛账户 password = '论坛密码' # 论坛密码 login_url = 'https://hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1' # post登录接口 request = requests.post(login_url, {"username": username, 'password': password}) # 登录一次,获取request cookie = request.cookies # 获取request里的cookie user_info = requests.get('https://hostloc.com/thread-%s-1-1.html'%(tilouid), cookies=cookie).text # formhash = re.search(r'formhash=\S{8}', user_info).group(0)[9:] # 积分中心使用re获取 while n < 1 : # if sys.platform=="win32": # os.system("cls") # elif sys.platform=="linux": # os.system("clear") try: user_info = requests.get('https://hostloc.com/thread-%s-1-1.html'%(tilouid), cookies=cookie).text Read_nowlou = int(re.search(r'xi1">(\d+).*xi1">(\d+)</span>', user_info).group(2)) # 当前楼层 # print("%s\r\n%s\r\n%s\r\n"%(formhash,msg,Read_nowlou)) if Read_nowlou == tiloun-2: posttime = int(time.time()) re_url = ('https://hostloc.com/forum.php?mod=post&action=reply&fid=45&tid=%d&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1'%(tilouid)) # post登录接口 request = requests.post(re_url, {"formhash":formhash, "message":msg,"usesig":1,"subject":"","posttime":posttime}, cookies=cookie).text print("跟贴成功") n=1 else: print("现在有%s楼|"%(Read_nowlou+1)) print (time.strftime("%Y-%m-%d %H:%M:%S------------------------------", time.localtime())) if tiloun-Read_nowlou>5: time.sleep(3) elif tiloun-Read_nowlou>4: time.sleep(0.01) elif tiloun-Read_nowlou==3: b=0 else: n=1 except: try: print ("出错了,按Ctrl+C停止脚本,2s后忽略错误继续执行.") time.sleep(1) print ("出错了,按Ctrl+C停止脚本,1s后忽略错误继续执行.") time.sleep(1) print ("出错了,按Ctrl+C停止脚本,0s后忽略错误继续执行.") except KeyboardInterrupt: n=1 print ("停止脚本执行.")
- 我的微信
- 这是我的微信扫一扫
-
- 我的微信公众号
- 我的微信公众号扫一扫
-