本篇內(nèi)容主要講解“python怎么實(shí)現(xiàn)自動(dòng)登陸Discuz論壇打卡簽到”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“python怎么實(shí)現(xiàn)自動(dòng)登陸Discuz論壇打卡簽到”吧!
10年積累的成都網(wǎng)站制作、成都做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有交口免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
# -*- coding: utf-8 -*- import requests import hashlib import re username = '' ###賬號(hào)### password = ''###密碼### UA = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) \ Chrome/27.0.1453.116 Safari/537.36" headers = { "User-Agent": UA, "Host": "bbs.hshy.net" } class hshy(object): def __init__(self, username, password, number = None, login_url = 'http://bbs.hshy.net/member.php', checkin_url = 'http://bbs.hshy.net/plugin.php'): self.username = username.decode('UTF-8').encode('GBK') self.password = hashlib.md5(password).hexdigest() self.number = number self.login_url = login_url self.checkin_url = checkin_url self.hshy_session = requests.Session() def try_login(self): rqs = self.hshy_session.get(self.login_url,params = {"referer":'', "mod": "logging", "action":"login"},headers = headers).text loginhash = re.search(r'',rqs).group(1).encode('ascii') formhash = re.search(r'',rqs).group(1).encode('ascii') post_data = {'answer':'', 'formhash':formhash, 'loginfield':'username', 'password':self.password, 'questionid':0, 'referer':'http://bbs.hshy.net/./', 'username':self.username} postrqs = self.hshy_session.post(self.login_url,params = {'mod':'logging', 'action':'login', 'loginsubmit':'yes', 'loginhash':loginhash, 'inajax':1},data = post_data,headers = headers) if re.search(u'現(xiàn)在將轉(zhuǎn)入登錄前頁面',postrqs.text): return 'login successful' else: self.notify() exit() #獲取打卡post的formhash參數(shù) def checkinformhash(self): checkinformhash = self.hshy_session.get(self.checkin_url,params = {'id': "dsu_amupper:ppering", "infloat": "yes", "handlekey":"pper", "referer": "http://bbs.hshy.net/", "inajax": 1, "ajaxtarget": "fwin_content_pper"},headers = headers).text return re.search(r'pper&ppersubmit=true&formhash=(.+?)\'',checkinformhash).group(1).encode('ascii') #失敗發(fā)送短信提醒 def notify(self): """ 使用nexmo發(fā)送提醒短信,如若使用需注冊nexmo服務(wù),將得到key和secret以調(diào)用其API~~ """ if self.number: key = '' ###你的Key secret = '' ###你的Secret data = {'api_key': key, 'api_secret': secret, 'from': 'anywhere', 'to': self.number, 'type': 'unicode', 'text': u'登陸或領(lǐng)取失敗,請手動(dòng)領(lǐng)取' } rps = requests.post('https://rest.nexmo.com/sms/json',data = data) return rps.text else: pass def checkin(self): self.try_login() params = { 'id':'dsu_amupper:pper', 'ppersubmit':'true', 'formhash':self.checkinformhash(), 'infloat':'yes', 'handlekey' :'dsu_amupper', 'referer': 'http://bbs.hshy.net/', 'inajax':1, 'ajaxtarget': 'fwin_content_dsu_amupper'} checkin = self.hshy_session.get(self.checkin_url,params = params ,headers = headers) if re.search(u'恭喜',checkin.text): print u'checkin successful' else: print u'checkin failed' self.notify() if __name__ == '__main__': hshy(username,password).checkin()到此,相信大家對(duì)“python怎么實(shí)現(xiàn)自動(dòng)登陸Discuz論壇打卡簽到”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
分享標(biāo)題:python怎么實(shí)現(xiàn)自動(dòng)登陸Discuz論壇打卡簽到
標(biāo)題鏈接:http://weahome.cn/article/jjgdeh.html