You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用RSelenium启动Firefox时加载驱动失败,出现504错误

问题描述

使用RSelenium打开Firefox浏览器时触发如下错误:

Warning: cannot open URL 'https://api.bitbucket.org/2.0/repositories/ariya/phantomjs/downloads?pagelen=100': HTTP status was '504 Gateway Timeout'Error in open.connection(con, "rb") : 
  cannot open the connection to 'https://api.bitbucket.org/2.0/repositories/ariya/phantomjs/downloads?pagelen=100' . 

此前功能正常,已重装RSelenium并重启RStudio,问题仍存在。

问题原因
  • RSelenium初始化时默认会尝试自动下载PhantomJS,但PhantomJS已停止维护,其官方Bitbucket仓库的下载接口出现网关超时(504错误),导致连接失败。
  • 即便目标是启动Firefox,RSelenium的默认配置仍会触发PhantomJS的下载检测,这是本次报错的直接原因。
解决办法

方法1:直接指定Firefox驱动,跳过PhantomJS下载

目标是使用Firefox,完全不需要依赖PhantomJS,初始化时明确禁用它:

library(RSelenium)
# 启动Firefox驱动,关闭PhantomJS自动下载
driver <- rsDriver(browser = "firefox", phantomjs = FALSE)
remDr <- driver[["client"]]

# 测试功能:打开示例页面
remDr$navigate("https://www.example.com")

注意:确保本地已安装geckodriver(Firefox的驱动程序),且路径已加入系统环境变量。如果没安装,下载对应系统版本的geckodriver,解压后放到R安装目录的bin文件夹,或者系统PATH包含的文件夹中。

方法2:通过环境变量禁用PhantomJS检测

设置环境变量让RSelenium跳过PhantomJS的下载检查:

library(RSelenium)
Sys.setenv(RSELENIUM_PRETEND_PHANTOMJS = "TRUE")
driver <- rsDriver(browser = "firefox")
remDr <- driver[["client"]]

方法3:排查网络问题

504错误也可能是本地网络无法访问Bitbucket导致的,手动访问报错里的URL,确认网络是否能正常连接;如果是网络限制,切换稳定网络或调整代理设置。

内容的提问来源于stack exchange,提问作者lucky13

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 19:49:53