python怎么实现自动登陆Discuz论坛打卡签到
本篇内容主要讲解“python怎么实现自动登陆Discuz论坛打卡签到”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python怎么实现自动登陆Discuz论坛打卡签到”吧!
10年积累的成都网站制作、成都做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站设计后付款的网站建设流程,更有交口免费网站建设让你可以放心的选择与我们合作。
# -*- coding: utf-8 -*- import requests import hashlib import re username = '' ###账号### 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'现在将转入登录前页面',postrqs.text): return 'login successful' else: self.notify() exit() #获取打卡post的formhash参数 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') #失败发送短信提醒 def notify(self): """ 使用nexmo发送提醒短信,如若使用需注册nexmo服务,将得到key和secret以调用其API~~ """ if self.number: key = '' ###你的Key secret = '' ###你的Secret data = {'api_key': key, 'api_secret': secret, 'from': 'anywhere', 'to': self.number, 'type': 'unicode', 'text': u'登陆或领取失败,请手动领取' } 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()到此,相信大家对“python怎么实现自动登陆Discuz论坛打卡签到”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
当前文章:python怎么实现自动登陆Discuz论坛打卡签到
标题链接:http://lswzjz.com/article/jjgdeh.html