從第一次報道到現在已經6年了。https://github.com/SeleniumHQ/selenium/issues/854
從這里https://chromedriver.chromium.org/getting-started我嘗試了這個代碼:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.)
driver.get('http://www.google.com/')。
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(60) # Let the user actually see something!
driver.quit()
當它啟動的時候,去chrome://version/看看:
組態檔路徑 C:UsersUSERCU~1AppDataLocalTempscoped_dir13280_930640861Default
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:Usersuser123AppDataLocalGoogleChromeUser DataProfile 16"/span>) #Path to your chrome profile。
w = webdriver.Chrome(executable_path="C:Userschromedriver.exe"/span>, chrome_options=options)
但是它沒有使用指定的路徑,而是在另一個組態檔的路徑中創建了組態檔,所以chrome://version顯示:
組態檔路徑 C:UsersusercuhuhAppDataLocalGoogleChromeUser DataProfile 16Default
那么問題來了,Default檔案夾被自動添加到指定的user-data-dir。我怎樣才能繞過它并啟動真正的組態檔16呢?
uj5u.com熱心網友回復:
首先
將你的ChromeDriver更新到最新版本
(這部分是必須的)。
然后將兩個引數--profile-directory=Profile 1和user-data-dir=C:Usersuser123AppDataLocalGoogleChromeUser DataProfile 16傳遞給Chrome二進制程式
options = Options()
options.add_argument('-profile-directory=Profile 16')
options.add_argument("user-data-dir=C:UsersHanaAppDataLocalGoogleChromeUser Data") #Path to your chrome profile[/span]。
driver = webdriver.Chrome(executable_path="C:chromedriver.exe"/span>, options=options)
注意,在user-data-dir中,你應該只傳遞所有組態檔的路徑,然后通過--profile-directory
您可以查看 Github 上 PythonChromeProfile 的完整源代碼,該代碼是我成功測驗的。你也可以閱讀關于創建Chrome組態檔的內容,并找到該組態檔的路徑這里
。轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/327076.html
標籤:
