我的硒驅動程式不會打開我的 chrome 組態檔。Chrome 驅動程式與我的 chrome 版本相同。它只是打開干凈的瀏覽器。
這是代碼:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
browser.get("https://google.com")
一些錯誤代碼是否有幫助:
[8052:3876:0303/141810.953:ERROR:device_event_log_impl.cc(214)] [14:18:10.953] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8052:3876:0303/141810.965:ERROR:device_event_log_impl.cc(214)] [14:18:10.965] USB: usb_device_handle_win.cc:1049 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[8052:3988:0303/141810.995:ERROR:chrome_browser_main_extra_parts_metrics.cc(239)] END: GetDefaultBrowser()
uj5u.com熱心網友回復:
試試這個:從 chrome://version/ 復制組態檔路徑
例如 C:\Users\pcuser\AppData\Local\Google\Chrome\User Data\Default
opt = webdriver.ChromeOptions()
opt.binary_location = r'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
chromedriver_exe_location = os.path.join(os.getcwd(), 'chromedriver.exe')
profile_path = r'C:\\Users\\fruhd\\AppData\\Local\\Google\\Chrome\\User Data' # path minus last folder
opt.add_argument('--user-data-dir={}'.format(profile_path))
opt.add_argument('--profile-directory={}'.format('DEFAULT')) # last folder name
driver = webdriver.Chrome(chromedriver_exe_location, options=opt, service_args='')
uj5u.com熱心網友回復:
您定義了optins但僅在創建 Web 驅動程式實體之后才在其中添加了值,因此這將不起作用。
你應該把線
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
前
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
請試試這個:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument("user-data-dir=C:/Users/Rektl/AppData/Local/Google/Chrome/User Data/Profile 2")
browser = webdriver.Chrome(executable_path="C:/Users/rektl/Desktop/csdd projekts/chromedriver.exe", chrome_options=options)
browser.get("https://google.com")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/436701.html
上一篇:查找檔案中的最大數字
