We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
B站的cookies最近总是失效,我写了一个自动获取cookies的python程序,使用方法很简单,传递参数-R时,将打开www.bilibili.com供用户登录账号;当直接运行时,将打开https://api.bilibili.com/x/web-interface/nav/stat并监视网络活动,将cookies复制到剪贴板。 请问大佬,您能否将这个功能集成进您的拓展里,或使用类似思路(例如在potplayer-拓展-账户设置中提供打开网页登陆的选项)实现自动抓取cookies并每次打开potplayer时更新配置文件? 代码如下: python
import sys import os from PyQt5.QtCore import QUrl, QTimer from PyQt5.QtWebEngineWidgets import QWebEngineView from PyQt5.QtWidgets import QApplication, QMainWindow import pyperclip import argparse # 设置环境变量来避免警告 os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1" os.environ["QT_SCREEN_SCALE_FACTORS"] = "1" os.environ["QT_SCALE_FACTOR"] = "1" # 需要提取的Cookie参数,按指定顺序排列 REQUIRED_COOKIES = [ "buvid3", "b_nut", "_uuid", "enable_web_push", "DedeUserID", "DedeUserID__ckMd5", "header_theme_version", "CURRENT_BLACKGAP", "buvid4", "rpdid", "buvid_fp_plain", "CURRENT_QUALITY", "SESSDATA", "bili_jct", "bili_ticket", "bili_ticket_expires", "hit-dyn-v2", "fingerprint", "buvid_fp", "bp_t_offset_22359752", "CURRENT_FNVAL", "home_feed_column", "browser_resolution", "sid", "b_lsid" ] class Browser(QMainWindow): def __init__(self, url, close_delay=3000): super().__init__() self.browser = QWebEngineView() self.setCentralWidget(self.browser) self.browser.setUrl(QUrl(url)) self.show() # 监听网络请求完成事件 self.browser.page().profile().cookieStore().cookieAdded.connect(self.onCookieAdded) self.cookies_dict = {} # 设置关闭时间和刷新时间 QTimer.singleShot(1000, self.refreshPage) QTimer.singleShot(close_delay, self.closeBrowser) def onCookieAdded(self, cookie): # 当新的Cookie被添加时,提取它们并过滤,筛除重复参数 cookie_str = cookie.toRawForm().data().decode('utf-8') for c in REQUIRED_COOKIES: if cookie_str.startswith(c + "="): self.cookies_dict[c] = cookie_str break def refreshPage(self): self.browser.reload() def closeBrowser(self): self.close() def getFormattedCookies(self): # 按照指定顺序格式化Cookies sorted_cookies = [self.cookies_dict[c] for c in REQUIRED_COOKIES if c in self.cookies_dict] cookie_str = "; ".join(sorted_cookies) formatted_cookie = f'"cookie": "{cookie_str}"' return formatted_cookie def closeEvent(self, event): # 在窗口关闭时输出Cookies到终端和剪贴板 formatted_cookies = self.getFormattedCookies() print(formatted_cookies) pyperclip.copy(formatted_cookies) print("Cookies已复制到剪贴板") super().closeEvent(event) def monitor_nav_stat(): # 打开指定API的URL并监视Cookie app = QApplication(sys.argv) window = Browser("https://api.bilibili.com/x/web-interface/nav/stat") app.exec_() def login_and_save_cookies(): # 打开Bilibili主页并让用户登录 app = QApplication(sys.argv) window = Browser("https://www.bilibili.com", close_delay=30000) # 延长关闭时间以便用户登录 app.exec_() def main(): parser = argparse.ArgumentParser(description="内嵌浏览器并监视网络活动") parser.add_argument('-R', action='store_true', help="打开www.bilibili.com供用户登录") args = parser.parse_args() if args.R: login_and_save_cookies() else: monitor_nav_stat() if __name__ == "__main__": main()
The text was updated successfully, but these errors were encountered:
使用无痕模式登录,获取cookie后手动删除cookie #62
Sorry, something went wrong.
No branches or pull requests
B站的cookies最近总是失效,我写了一个自动获取cookies的python程序,使用方法很简单,传递参数-R时,将打开www.bilibili.com供用户登录账号;当直接运行时,将打开https://api.bilibili.com/x/web-interface/nav/stat并监视网络活动,将cookies复制到剪贴板。
请问大佬,您能否将这个功能集成进您的拓展里,或使用类似思路(例如在potplayer-拓展-账户设置中提供打开网页登陆的选项)实现自动抓取cookies并每次打开potplayer时更新配置文件?
代码如下:
python
The text was updated successfully, but these errors were encountered: