Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中将默认Chrome配置文件与Selenium一起使用_Python_Selenium_Google Chrome - Fatal编程技术网

在Python中将默认Chrome配置文件与Selenium一起使用

在Python中将默认Chrome配置文件与Selenium一起使用,python,selenium,google-chrome,Python,Selenium,Google Chrome,当我像这样推出含硒的Chrome时 from selenium import webdriver driver = webdriver.Chrome("/path/to/chromedriver") 。。。我得到了一个“干净”的Chrome实例,没有浏览历史记录,也没有在计算机上正常安装Chrome时存储的数据 我想用Selenium打开Chrome,但在打开的浏览器中可以使用默认Chrome安装的书签、历史记录、cookie、缓存等 我该怎么做?如果您只是想打开一个新浏览器,可以使用Sele

当我像这样推出含硒的Chrome时

from selenium import webdriver
driver = webdriver.Chrome("/path/to/chromedriver")
。。。我得到了一个“干净”的Chrome实例,没有浏览历史记录,也没有在计算机上正常安装Chrome时存储的数据

我想用Selenium打开Chrome,但在打开的浏览器中可以使用默认Chrome安装的书签、历史记录、cookie、缓存等


我该怎么做?

如果您只是想打开一个新浏览器,可以使用Selenium创建一个连接了Chrome的新驱动程序。您需要从下载chrome驱动程序,并将其置于如下所示的路径中

以下是python代码:

from selenium import webdriver

driver = webdriver.Chrome("path-to-chromedriver")
driver.get("https://www.google.com/")

您可以使用特定的配置文件,也可以使用问题中的默认配置文件:

如何使用Python中的Selenium在Chrome中打开新的默认浏览器窗口

这里是一个设置的剪贴:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=THE/PATH/TO/YOUR/PROFILE") # change to profile path
chrome_options.add_argument('--profile-directory=Profile 1')

browser = webdriver.Chrome(executable_path="PATH/TO/cromedriver.exe", chrome_options=chrome_options) # change the executable_path too
要找到配置文件的路径,只需键入
chrome://version/
在您默认的chrome浏览器中,您将在配置文件路径下看到它:在我的电脑中,它是
“C:\Users\user\AppData\Local\Google\chrome\user Data\default”


希望这对你有帮助

我想在默认浏览器(Chrome)中打开浏览器窗口。谢谢你的建议。但它并没有像我想的那样工作。它没有显示默认浏览器的书签和历史记录。请进一步建议。您可以使用您的个人资料。。。不是默认的。。。我将为公众添加答案…@BirajRaj我在答案中添加了以下内容:
chrome\u选项。添加参数('--profile directory=profile 1')
@BirajRaj我仍然认为编辑您的问题是个好主意。。。这可以帮助其他人解决这个问题。。。