Python Playwright无法加载默认以外的自定义浏览器配置文件
问题:Playwright launch_persistent_context无法加载自定义Chrome配置文件
我想用Playwright的launch_persistent_context方法打开自定义Chrome配置文件,当前代码如下:
import asyncio from playwright.async_api import async_playwright import os async def main(): # Initialize Playwright and launch a browser async with async_playwright() as playwright: print("Launching browser") browser = await playwright.chromium.launch_persistent_context(user_data_dir=fr'C:\Users\{os.getlogin()}\AppData\Local\Google\Chrome\User Data\Profile 1', headless=False) # Create a new page in the browser print("Creating new page") page = await browser.new_page() print("Going to URL") # Navigate to a website await page.goto("https://www.example.com") input("Press Enter to continue...") # Close the browser await browser.close() # Run the main function in an asyncio event loop asyncio.run(main())
当user_data_dir传入Chrome的"User Data"文件夹路径时,浏览器能正常以默认配置文件启动;但指定类似...\User Data\Profile 1的自定义配置路径时,浏览器虽能启动,却没有加载对应的配置文件。
我已经尝试了以下方案,但问题仍未解决:
- 查阅Playwright官方文档,未找到加载默认以外自定义配置文件的详细说明;
- 直接指定自定义配置文件路径,结果仍无法加载配置。
内容的提问来源于stack exchange,提问作者Zeeshan Ghazanfar
相关产品推荐
相关产品推荐

