Spaces:
Runtime error
Runtime error
File size: 2,204 Bytes
aaee22d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
"""
从 Chrome 导出 NotebookLM 认证信息
方法:使用 Chrome Remote Debugging 连接已登录的浏览器
步骤:
1. 关闭所有 Chrome 窗口
2. 用以下命令启动 Chrome(开启远程调试):
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
3. 在 Chrome 中登录 https://notebooklm.google.com
4. 运行此脚本
"""
import asyncio
import json
import os
async def export_auth():
try:
from playwright.async_api import async_playwright
except ImportError:
print("请先安装: pip install playwright")
return
storage_path = os.path.expanduser("~/.notebooklm/storage_state.json")
os.makedirs(os.path.dirname(storage_path), exist_ok=True)
print("正在连接到 Chrome (端口 9222)...")
print("确保你已用以下命令启动 Chrome:")
print(' "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" --remote-debugging-port=9222')
print()
async with async_playwright() as p:
try:
browser = await p.chromium.connect_over_cdp("http://127.0.0.1:9222")
print("✅ 已连接到 Chrome")
except Exception as e:
print(f"❌ 无法连接: {e}")
print("\n请确保:")
print("1. 关闭所有 Chrome 窗口")
print("2. 用远程调试模式启动 Chrome")
return
# 获取默认上下文
contexts = browser.contexts
if not contexts:
print("❌ 没有找到浏览器上下文")
return
context = contexts[0]
# 保存 storage state
await context.storage_state(path=storage_path)
print(f"\n✅ 认证信息已保存到: {storage_path}")
# 读取并显示
with open(storage_path, "r", encoding="utf-8") as f:
content = f.read()
print("\n" + "=" * 60)
print("复制以下内容作为 HF Space Secret (NOTEBOOKLM_AUTH_JSON):")
print("=" * 60)
print(content)
if __name__ == "__main__":
asyncio.run(export_auth())
|