#脚本#loc 无服务器函数 签到脚本
主机社 9月前

#-*- coding=utf-8 -*-import requestsimport reimport sysimport urllib3import timeurllib3.disable_warnings()index='https://www.hostloc.com/'page_url='https://www.hostloc.com/forum-45-1.html'credit_url='https://www.hostloc.com/home.php?mod=spacecp&ac=credit&showcredit=1'login_url='https://www.hostloc.com/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1'login_data={        'fastloginfield':'username'        ,'username':''        ,'cookietime':'2592000'        ,'password':''        ,'quickforward':'yes'        ,'handlekey':'ls'    }headers={    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'    ,'Accept-Encoding':'gzip, deflate, sdch'    ,'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6'    ,'Host':'www.hostloc.com'    ,'Referer':'https://www.hostloc.com/forum.php'    ,'Upgrade-Insecure-Requests':'1'    ,'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}class HostLoc():    def __init__(self,username,passwd):        self.username=username        self.passwd=passwd        self.session=requests.Session()        self.session.headers=headers        login_data['username']=username        login_data['password']=passwd        login_data['formhash']=self.get_hidden_value(index,'formhash')        self.login()    def login(self):        self.session.post(login_url,data=login_data,verify=False)    def isLogin(self):        url='https://www.hostloc.com/home.php?mod=spacecp'        html=self.session.get(url).text        UserName=re.findall(self.username,html)        if len(UserName)==0:            return False        else:            return True    def get_credit(self):        html=self.session.get(credit_url,verify=False).text        credit_pattern=re.compile(u'</ul><ul class="creditl mtm bbda cl"><li class="xi1 cl"><em> 金钱: </em>(.*?)  .*? </li>[\w\W]*?<li><em> 威望: </em>(.*?) </li>[\w\W]*?<li class="cl"><em>积分: </em>(.*?) <span class="xg1">')        try:            credit=credit_pattern.findall(html)            coin,wh,jf=credit[0]            print(u"{} coin:{},wei wang:{},jifen:{}".format(self.username,coin,wh,jf))            return True        except Exception as e:            print(u"{} fetch data error!:{}".format(self.username,e))            return False    def get_user(self):        print('parse '+page_url)        self.html=self.session.get(page_url,verify=False).text        user_pattern=re.compile('space-uid-\d+?.html')        users=list(set(user_pattern.findall(self.html)))        self.users=[index+i for i in users]    def visit_user(self):        for user in self.users[:10]:            print('visit user '+user)            self.session.get(user)    def get_hidden_value(self,url,keyname):        r=self.session.get(url)        cont=r.text        value=re.findall('<input type="hidden" name="{}" value="(.*?)" />'.format(keyname),cont)[0]        return valuedef start():    #多用户配置    #格式为:[[username1,password1],[username2,password2],[username3,password3]]    users=[        ['user1','password1'],        ['user2','password2'],    ]    for username,passwd in users:        hostloc=HostLoc(username,passwd)        if hostloc.get_credit():            hostloc.get_user()            hostloc.visit_user()            hostloc.get_credit()def main_handler(event, context):    return start()if __name__=='__main__':    start()

发上我的脚本,搭配腾讯云scf(无服务器函数)每天自动签到,scf配置内容:

设置好用户名和密码,支持多用户签到

作者:Abbey

支持作者:https://abbeyok.com/

查看原帖:https://www.hostloc.com/thread-516292-1-1.html

最新回复 (0)
返回
网站标签