【发布时间】:2018-03-23 05:10:57
【问题描述】:
尝试将 python 项目(使用 selenium 抓取 Twitter 推文而不使用 limited twitter api)转换为 R 编程。在 Python 中工作正常,但我想在 R 中重新创建它。R 新手,但如果有帮助,我有一些 MatLab 经验
install.packages("RSelenium") # install RSelenium 1.7.1
据我所知,该软件包已更新。因此,我需要使用其他功能,而不是 startserver()。但根据所有研究,我得到的答案有点矛盾,但都不起作用:
require(RSelenium) #used require() and library()
remDr <- remoteDriver(browserName = "chrome")
remDr$open()
我得到错误:
[1] "Connecting to remote server"
Error in checkError(res) :
Undefined error in httr call. httr output: Failed to connect to localhost port 4444: Connection refused
也试过了:
require(RSelenium)
remDr <- rsDriver(browser = c("chrome"))
我得到:
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] "Connecting to remote server"
chrome 浏览器 (61.0.3163.100) 启动,但由于最后一行,我无法运行我的代码的下一行。浏览器在自动关闭之前保持打开大约半分钟,我收到此错误:
Selenium message:unknown error: unable to discover open pages
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.44 seconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'RENTEC-THINK', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: unknown
Error: Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
Further Details: run errorDetails method
我尝试了多种不同的方法,包括下载 chrome 驱动程序(v2.33 应该支持 chrome v60-62 https://sites.google.com/a/chromium.org/chromedriver/downloads) 并在 removedriver 中包含路径或将路径添加为系统变量
就像我所做的任何事情都不起作用,好像 RSelenium 的更新搞砸了一切。我在做傻事吗?
我已经到了这样的地步,从我在网上看到的所有不一致的答案中,我发现自己在尝试不同代码行的不同组合,混合匹配所有内容等,拼命尝试让这个工作仅通过反复试验
我的下一个尝试是尝试找出 R 安装 RSelenium 的位置,然后查看代码中的内容:(
我也在考虑 docker,但我并没有真正为了让我的代码工作而安装单独的应用程序。
【问题讨论】: