• 本帖最后由 Abbey 于 2019-1-21 13:59 编辑 *

![](0074MymAgy1fze5g41e04j314k0nvdml.jpg)

  • #-- coding=utf-8 --
  • import requests
  • import re
  • import sys
  • import urllib3
  • import time
  • - urllib3.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' 金钱: (.?) .? [\w\W]?- 威望: (.?) [\w\W]?积分: (.?) ')
  • 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(''.format(keyname),cont)[0]
  • return value
  • - - def 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配置内容:

![](0074MymAly1fze5jiajsrj30ij0fgq3l.jpg)

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