import requests import re import json import time import random class bobbySession(requests.Session): def __init__(self,account:str,password:str) -> None: super().__init__() self.account = account self.password = password try: self.Refresh() except: raise SystemError("无法连接到bobby皮肤站") def Refresh(self): self.__XSRF_COOKIE_Init() self.__Login(self.account,self.password) def __XSRF_COOKIE_Init(self) : url = r"https://www.bobbyskin.com/auth/login" html = self.get(url) # 正则查找 pattern = r'^]*)>' txt = html.text pattern2 = r'(?<=content=)"[^"]*"' res1 = re.search(pattern,txt) if res1 is None: raise ValueError("cant find xsrf token") res2 = re.search(pattern2,res1[0]) if res2 is None : raise ValueError("cant find xsrf token") self.headers['X-Csrf-Token'] = res2[0].replace('"',"") return # 登录初始化 def __Login(self,account:str,password:str): body = { "identification" : account, "keep" : "true", "password" : password } resp = self.post(r"https://www.bobbyskin.com/auth/login",json=body) # 生成邀请码 def __GenerateInvite (self) : xsrf = self.headers.get("X-Csrf-Token") if xsrf is None : raise requests.RequestException("XSRF expired or unavailable") body = { "_token" : xsrf, "description" : time.strftime("%Y%m%d%H%M%S") } res = self.post(r"https://www.bobbyskin.com/admin/invitation-codes/generate",data=body) # print(res.text,res.status_code) # 查找可用邀请码 def __getInvite(self)->list[str]: url = "https://www.bobbyskin.com/admin/invitation-codes" tablePattern = r'
((?!)[\S\s])*' codePattern = r'(?<=