擅长:python、mysql、java
<p>这就是它最终为我工作的原因。</p>
<pre><code>from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)
</code></pre>
<p>要查找chrome配置文件数据的路径,需要在地址栏中键入<code>chrome://version/</code>。例如,我的显示为<code>C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default</code>,要在脚本中使用它,我必须排除<code>\Default\</code>,因此我们最终只得到<code>C:\Users\pc\AppData\Local\Google\Chrome\User Data</code>。</p>
<p>另外,如果您只想为selenium创建单独的配置文件:将路径替换为任何其他路径,如果启动时不存在,chrome将为其创建新的配置文件和目录。</p>