Bir*_*Raj 5 python selenium google-chrome
当我像这样用Selenium启动Chrome时...
from selenium import webdriver
driver = webdriver.Chrome("/path/to/chromedriver")
Run Code Online (Sandbox Code Playgroud)
...我得到了一个“干净”的Chrome实例,该实例没有浏览历史记录,并且我的计算机上正常安装的Chrome都没有存储的数据。
我想使用Selenium打开Chrome,但是在打开的浏览器中可以使用默认Chrome安装中的书签,历史记录,Cookie,缓存等。
我怎样才能做到这一点?
您可以使用特定的配置文件或默认配置文件,如您的问题所示:
如何使用 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
Run Code Online (Sandbox Code Playgroud)
要查找配置文件的路径,只需chrome://version/
在默认的 Chrome 浏览器中输入,您就会在配置文件路径下看到它:在我的电脑中,它是"C:\Users\user\AppData\Local\Google\Chrome\User Data\Default"
希望您觉得这有帮助!
Lin*_*nny -3
如果您只是想打开一个新的浏览器,您可以使用 Selenium 创建一个附加 Chrome 的新驱动程序。您需要从此处下载 chrome 驱动程序,并将其放在如下所示的路径中。
这是Python代码:
from selenium import webdriver
driver = webdriver.Chrome("path-to-chromedriver")
driver.get("https://www.google.com/")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1211 次 |
最近记录: |