删除LICENSE.chromedriver后RSelenium的rsDriver仍报错求助
RSelenium调用rsDriver时的Chrome连接问题
我在使用RSelenium调用rsDriver()时遇到无法连接Chrome的问题,执行以下代码:
rD <- rsDriver(port=free_port(random=TRUE),browser="chrome",chromever="109.0.5414.25",verbose=FALSE)
得到错误:
Could not open chrome browser. Client error message: Undefined error in httr call. httr output: Failed to connect to localhost port 795: Connection refused Check server log for further details. Warning message: In rsDriver(port = free_port(random = TRUE), browser = "chrome", : Could not determine server status.
我已经尝试删除LICENSE.chromedriver文件,但问题仍未解决。
相关命令输出
selenium(retcommand = T)的输出:
> library(wdman) > selenium(retcommand = T) checking Selenium Server versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking chromedriver versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking geckodriver versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking phantomjs versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD [1] "C:\\PROGRA~1\\COMMON~1\\Oracle\\Java\\javapath\\java.exe -Dwebdriver.chrome.driver=\"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_chromedriver\\win32\\110.0.5481.30/chromedriver.exe\" -Dwebdriver.gecko.driver=\"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_geckodriver\\win64\\0.32.0/geckodriver.exe\" -Dphantomjs.binary.path=\"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_phantomjs\\windows\\2.1.1/phantomjs-2.1.1-windows/bin/phantomjs.exe\" -jar \"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_seleniumserver\\generic\\4.0.0-alpha-2/selenium-server-standalone-4.0.0-alpha-2.jar\" -port 4567"
- 将
chromever改为"110.0.5481.30"后的错误信息:
> rD <- rsDriver(port=free_port(random=TRUE),browser="chrome",chromever="110.0.5481.30",verbose=FALSE)
Selenium提示:会话创建失败:该版本ChromeDriver仅支持Chrome 110版本 当前浏览器版本为109.0.5414.75,二进制文件路径:C:\Program Files\Google\Chrome\Application\chrome.exe Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10' System info: host: 'EC2AMAZ-1JRGETJ', ip: '172.31.9.48', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1' Driver info: driver.version: unknown remote stacktrace: Backtrace: (No symbol) [0x00C53643] (No symbol) [0x00BE8981] (No symbol) [0x00AEB35D] (No symbol) [0x00B0ED2D] (No symbol) [0x00B09B50] (No symbol) [0x00B06F89] (No symbol) [0x00B41EB5] (No symbol) [0x00B41B0C] (No symbol) [0x00B3B1F6] (No symbol) [0x00B10D57] (No symbol) [0x00B124FD] GetHandleVerifier [0x00ECB5F2+2513186] GetHandleVerifier [0x00EFB730+2710112] GetHandleVerifier [0x00EFECDC+2723852] GetHandleVerifier [0x00D02250+640384] (No symbol) [0x00BF1142] (No symbol) [0x00BF6AD8] (No symbol) [0x00BF6BBB] (No symbol) [0x00C009FB] BaseThreadInitThunk [0x768262C4+36] RtlSubscribeWnfStateChangeNotification [0x76F31B69+1081] RtlSubscribeWnfStateChangeNotification [0x76F31B34+1028] Could not open chrome browser. Client error message: Summary: SessionNotCreatedException Detail: 无法创建新会话。 Further Details: 运行errorDetails方法查看更多信息 Check server log for further details.
binman::list_versions("chromedriver")的输出:
> library(binman) > list_versions("chromedriver") $win32 [1] "100.0.4896.20" "100.0.4896.60" "101.0.4951.15" "101.0.4951.41" "102.0.5005.27" [6] "102.0.5005.61" "103.0.5060.24" "103.0.5060.53" "104.0.5112.20" "104.0.5112.29" [11] "106.0.5249.61" "107.0.5304.18" "107.0.5304.62" "108.0.5359.22" "108.0.5359.71" [16] "109.0.5414.25" "109.0.5414.74" "110.0.5481.30" "96.0.4664.45" "97.0.4692.20" [21] "97.0.4692.36" "97.0.4692.71" "98.0.4758.48" "98.0.4758.80" "99.0.4844.17" [26] "99.0.4844.35" "99.0.4844.51"
- 本地Chrome版本:
Chrome已更新至最新版本 Version 109.0.5414.75 (Official Build) (64-bit)
selenium(retcommand = T, chromever = "109.0.5414.25")的输出:
> selenium(retcommand = T,chromever = "109.0.5414.25") checking Selenium Server versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking chromedriver versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking geckodriver versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD checking phantomjs versions: BEGIN: PREDOWNLOAD BEGIN: DOWNLOAD BEGIN: POSTDOWNLOAD [1] "C:\\PROGRA~1\\COMMON~1\\Oracle\\Java\\javapath\\java.exe c(\"-Dwebdriver.chrome.driver=\\\"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\binman\\\\binman_chromedriver\\\\win32\\\\109.0.5414.25/chromedriver.exe\\\"\", \"-Dwebdriver.chrome.driver=\\\"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\binman\\\\binman_chromedriver\\\\win32\\\\109.0.5414.25/LICENSE.chromedriver\\\"\") -Dwebdriver.gecko.driver=\"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_geckodriver\\win64\\0.32.0/geckodriver.exe\" -Dphantomjs.binary.path=\"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_phantomjs\\windows\\2.1.1/phantomjs-2.1.1-windows/bin/phantomjs.exe\" -jar \"C:\\Users\\Administrator\\AppData\\Local\\binman\\binman_seleniumserver\\generic\\4.0.0-alpha-2/selenium-server-standalone-4.0.0-alpha-2.jar\" -port 4567"
解决方案
从输出可以看到,指定chromever="109.0.5414.25"时,生成的Selenium启动命令重复设置了-Dwebdriver.chrome.driver,同时指向了chromedriver.exe和LICENSE.chromedriver文件,这会导致驱动加载失败。按以下步骤解决:
- 清理缓存目录:删除
C:\Users\Administrator\AppData\Local\binman\binman_chromedriver\win32\109.0.5414.25整个文件夹,彻底清除损坏的驱动文件。 - 安装匹配的ChromeDriver:本地Chrome版本是109.0.5414.75,选择列表中最接近的
109.0.5414.74版本安装:wdman::chrome_install("109.0.5414.74") - 调用rsDriver时指定正确版本:
rD <- rsDriver(port=free_port(random=TRUE), browser="chrome", chromever="109.0.5414.74", verbose=FALSE) - 更新Selenium Server:当前使用的是老旧的4.0.0-alpha-2版本,建议更新到稳定版:
wdman::selenium_install(version = "4.8.0") # 或最新稳定版本号
内容的提问来源于stack exchange,提问作者AKshayKulkarni
相关产品推荐
相关产品推荐

