Playwright中可以使用storage_state直接保存cookies数据

可以直接使用Playwright 提供的 API 手动实现 --save-storage 的功能
存储
context.storage_state(path=“storage.json”
调用
context = browser.new_context(storage_state=“storage.json)”)

1 Like

问题是如何使用 Playwright 的 storage_state() 方法手动保存和加载浏览器上下文的存储(cookies、localStorage、sessionStorage)。您需要将存储状态保存到一个文件中,并在之后加载该文件以恢复会话。这通常用于模拟登录状态或保持会话数据。