调用接口识别验证码登录获得会话,检测是否为置顶文章,如果为置顶、终止程序,如果不为置顶,反序列化上一次存储的文章ID对象,然后删除上一次的文章,重发文章,并且将这一次文章的ID对象序列化存储起来以备下一次删除文章使用。
import requestsimport jsonimport datetimeimport timeimport ddddocrimport pickledef GetAuthCode():ocr = ddddocr.DdddOcr()while True:timestamp = int(round(time.time() * 1000))authcode_url = 'http://bbs.jxusptpay.com/AheadBBS/authCode?timestamp=' + str(timestamp)resp = session.get(url=authcode_url)res = ocr.classification(resp.content)if len(res)==4 and res.isdigit():authcode = resbreakreturn authcodedef BbsLogin():authcode = GetAuthCode()login_url = "http://bbs.jxusptpay.com:80/AheadBBS/login"login_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0","Accept": "application/json, text/javascript, */*; q=0.01","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate", "X-Requested-With": "XMLHttpRequest","Content-Type": "multipart/form-data; boundary=---------------------------16809288341427122629986944614"}login_data = "-----------------------------16809288341427122629986944614\r\n" \"Content-Disposition: form-data; name=\"token\"\r\n" \"\r\n" \"\r\n" \"-----------------------------16809288341427122629986944614\r\n" \"Content-Disposition: form-data; name=\"userName\"\r\n" \"\r\n学号\r\n" \"-----------------------------16809288341427122629986944614\r\n" \"Content-Disposition: form-data; name=\"passWord\"\r\n" \"\r\n密码\r\n" \"-----------------------------16809288341427122629986944614\r\n" \"Content-Disposition: form-data; name=\"authCode\"\r\n" \"\r\n{}\r\n" \"-----------------------------16809288341427122629986944614\r\n" \"Content-Disposition: form-data; name=\"rememberMe\"\r\n" \"\r\non\r\n" \"-----------------------------16809288341427122629986944614--\r\n".format(authcode)login_resp = session.post(url=login_url, headers=login_headers, data=login_data)login_resp_text = login_resp.textprint(login_resp_text)login_resp_msg = json.loads(login_resp_text)['msg']if login_resp_msg != '操作成功':exit()def IsTop():IsTop_res = FalseIsTop_url = "http://bbs.jxusptpay.com:80/AheadBBS/forum/page"IsTop_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0","Accept": "application/json, text/javascript, */*; q=0.01","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate", "X-Requested-With": "XMLHttpRequest","Content-Type": "multipart/form-data; boundary=---------------------------20290579884477568832630254930","Origin": "http://bbs.jxusptpay.com", "Connection": "close","Referer": "http://bbs.jxusptpay.com/AheadBBS/forum/1/all"}IsTop_data = "-----------------------------20290579884477568832630254930\r\n" \"Content-Disposition: form-data; name=\"page\"\r\n" \"\r\n1\r\n" \"-----------------------------20290579884477568832630254930\r\n" \"Content-Disposition: form-data; name=\"size\"\r\n" \"\r\n15\r\n" \"-----------------------------20290579884477568832630254930\r\n" \"Content-Disposition: form-data; name=\"blockId\"\r\n" \"\r\n1\r\n" \"-----------------------------20290579884477568832630254930\r\n" \"Content-Disposition: form-data; name=\"flag\"\r\n" \"\r\nall\r\n" \"-----------------------------20290579884477568832630254930--\r\n"IsTop_resp = session.post(url=IsTop_url, headers=IsTop_headers, data=IsTop_data)author_id = json.loads(IsTop_resp.text)['data']['records'][0]['author']['id']TopicTitle = json.loads(IsTop_resp.text)['data']['records'][0]['topicTitle']if author_id == 9069 and 'Hack For Fun' in TopicTitle:# 检查置顶帖子是否为我发的帖子IsTop_res = Truereturn IsTop_resdef CoverArticle():with open('Pickled_ArticleId', 'rb') as f_r:ArticleId = pickle.load(f_r)['ArticleId']cover_url = "http://bbs.jxusptpay.com:80/AheadBBS/topic/deleteTopic"cover_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0","Accept": "application/json, text/javascript, */*; q=0.01","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate", "X-Requested-With": "XMLHttpRequest","Content-Type": "multipart/form-data; boundary=---------------------------37687526140434614373731301627","Origin": "http://bbs.jxusptpay.com", "Connection": "close"}cover_data = "-----------------------------37687526140434614373731301627\r\n" \"Content-Disposition: form-data; name=\"topicId\"\r\n" \"\r\n{}\r\n" \"-----------------------------37687526140434614373731301627\r\n" \"Content-Disposition: form-data; name=\"userId\"\r\n" \"\r\n9069\r\n" \"-----------------------------37687526140434614373731301627--\r\n".format(ArticleId)cover_resp = session.post(url=cover_url, headers=cover_headers, data=cover_data)print(cover_resp.text)post_url = "http://bbs.jxusptpay.com:80/AheadBBS/topic/issue"post_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0","Accept": "application/json, text/javascript, */*; q=0.01","Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2","Accept-Encoding": "gzip, deflate", "X-Requested-With": "XMLHttpRequest","Content-Type": "multipart/form-data; boundary=---------------------------42572536836188666591267450352","Origin": "http://bbs.jxusptpay.com", "Connection": "close","Referer": "http://bbs.jxusptpay.com/AheadBBS/topic/create?blockInfoId=1"}post_data = "-----------------------------42572536836188666591267450352\r\n" \"Content-Disposition: form-data; name=\"topicTitle\"\r\n" \"\r\n\xe3\x80\x8e\xe6\xb1\x9f\xe8\xbd\xaf\xe4\xbf\xa1\xe5\xae\x89\xe4\xba\xa4\xe6\xb5\x81\xe7\xbe\xa4\xe3\x80\x8f Hack For Fun : )\r\n" \"-----------------------------42572536836188666591267450352\r\n" \"Content-Disposition: form-data; name=\"blockId\"\r\n" \"\r\n1\r\n" \"-----------------------------42572536836188666591267450352\r\n" \"Content-Disposition: form-data; name=\"topicContent\"\r\n" \"\r\n\r\n\xe6\xb1\x87\xe8\x81\x9a\xe6\x9c\xac\xe7\xa7\x91\xe4\xb8\x93\xe7\xa7\x91\xe5\xa4\x9a\xe5\xb1\x8a\xe4\xbf\xa1\xe5\xae\x89\xe5\xad\xa6\xe5\xad\x90
\r\n" \"\xe6\x96\x87\xe6\x98\x8e\xe5\x92\x8c\xe8\xb0\x90\xe7\x9a\x84\xe6\xb8\x97\xe9\x80\x8f\xe6\xb5\x8b\xe8\xaf\x95\xe3\x80\x81SRC\xe6\x8c\x96\xe6\xb4\x9e\xe3\x80\x81CTF\xe7\xab\x9e\xe8\xb5\x9b\xe7\xad\x89\xe5\xae\x89\xe5\x85\xa8\xe6\x8a\x80\xe6\x9c\xaf\xe4\xba\xa4\xe6\xb5\x81\xe7\xbe\xa4
\r\n" \"<Happy Hacking>
\r\n" \"\r\n" \"-----------------------------42572536836188666591267450352--\r\n"post_resp = session.post(url=post_url, headers=post_headers, data=post_data)data = {}ArticleId = json.loads(post_resp.text)['data']data['ArticleId'] = ArticleId[ArticleId.find('/')+1:]with open('Pickled_ArticleId', 'wb') as f_w:pickle.dump(data, f_w)print(post_resp.text)def FinalProcess():BbsLogin()IsTop_res = IsTop()if IsTop_res == True:exit('[+]: 当前帖子为校园综合论坛置顶帖子')else:CoverArticle()if __name__ == "__main__":start_time = datetime.datetime.now()print('\n[+] 脚本启动时间:{}'.format(start_time.strftime('%Y-%m-%d %H:%M:%S')))session = requests.session()FinalProcess()end_time = datetime.datetime.now()print('[+] 脚本运行时间:{} 秒\n'.format((end_time-start_time).total_seconds()))