def login(self): b = Bilibili() b.login(username=self.username, password=self.password) self.access_token = b.access_token self.sessdata = b._session.cookies['SESSDATA'] self.bili_jct = b._session.cookies['bili_jct'] print(f"login successfully! {self.name} {self.access_token} {self.sessdata} {self.bili_jct}") self.verify = Verify(sessdata=self.sessdata, csrf=self.bili_jct)
def login_handle(args): bilibili = Bilibili() if bilibili.login(username=args.username, password=args.password): bilibili.get_user_info() with open(os.path.join(bundle_dir, "cookies.json"), "w", encoding="utf-8") as f: f.write( json.dumps(bilibili.get_cookies(), ensure_ascii=False, indent=2))
raise accounts = [] for line in config['user']['account'].splitlines(): try: if line[0] == "#": continue pairs = {} for pair in line.strip(";").split(";"): if len(pair.split("=")) == 2: key, value = pair.split("=") pairs[key] = value password = all(key in pairs for key in ["username", "password"]) token = all(key in pairs for key in ["access_token", "refresh_token"]) cookie = all( key in pairs for key in ["bili_jct", "DedeUserID", "DedeUserID__ckMd5", "sid", "SESSDATA"]) if password or token or cookie: accounts.append(pairs) except: pass config['user'].pop("account") instance = Bilibili(config['global']['https'], Queue()) instance.login(force_refresh_token=False, **accounts[0]) sys.stdout = oristdout print( requests.cookies.get_cookie_header( instance._session.cookies, requests.Request('GET', 'https://www.bilibili.com')))