要跨会话保留 cookie 和网站首选项,需要在使用 Python Selenium 时启动 Chrome 及其默认配置文件Webdriver。
以下代码提供了解决方案:
<code class="python">from selenium import webdriver # Set path to default Chrome profile (exclude trailing "\Default") options = webdriver.ChromeOptions() path = "C:\Users\User\AppData\Local\Google\Chrome\User Data" options.add_argument(f"user-data-dir={path}") # Set path tochromedriver.exe w = webdriver.Chrome(executable_path="C:\Users\User\chromedriver.exe", chrome_options=options)</code>
为 Selenium 创建和使用单独的配置文件:
以上是如何使用 Python Selenium Webdriver 加载默认 Chrome 配置文件?的详细内容。更多信息请关注PHP中文网其他相关文章!