如何在Selenium Webdriver Python 3中使用Chrome配置文件
因此,每当我尝试通过添加来使用Chrome设置(我在默认浏览器中使用的设置)
So whenever I try to use my Chrome settings (the settings I use in the default browser) by adding
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\Users\... (my webdriver path)")
driver = webdriver.Chrome(executable_path="myPath", options=options)
它向我显示错误代码
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes n 16-17: truncated \UXXXXXXXX escape
以我的重击.我不知道这意味着什么,我会为我能得到的任何帮助而高兴.预先感谢!
in my bash. I don't know what that means and I'd be happy for any kind of help I can get. Thanks in advance!
如果您要打开 Chrome浏览器会话,请根据您的问题和代码试用以下选项:
As per your question and your code trials if you want to open a Chrome Browsing Session here are the following options:
-
要使用默认的 Chrome配置文件:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
注意:您的默认Chrome配置文件将包含许多书签,扩展名,主题,cookie等. Selenium 可能无法加载.因此,按照最佳做法,为您的 @Test 创建一个新的 chrome配置文件,并在配置文件中存储/保存/配置所需的数据.
Note: Your default chrome profile would contain a lot of bookmarks, extensions, theme, cookies etc. Selenium may fail to load it. So as per the best practices create a new chrome profile for your @Test and store/save/configure within the profile the required data.
要使用自定义的 Chrome配置文件:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\AtechM_03\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")
在这里您将找到有关如何进行详细讨论通过Python打开Chrome配置文件