So I'm not 100% sure this is possible, but I found a good solution in Ruby and in python, so I was wondering if something similar might work in R.
所以我不是100%确定这是可能的,但我在Ruby和python中找到了一个很好的解决方案,所以我想知道类似的东西是否可以在R中起作用
Basically, given a URL, I want to render that URL, take a screenshot of the rendering as a .png, and save the screenshot to a specified folder. I'd like to do all of this on a headless linux server.
基本上,给定一个URL,我想呈现该URL,将呈现的屏幕截图作为.png,并将屏幕截图保存到指定的文件夹。我想在无头的linux服务器上做这一切。
Is my best solution here going to be running system
calls to a tool like CutyCapt, or does there exist an R-based toolset that will help me solve this problem?
我最好的解决方案是运行系统调用CutyCapt这样的工具,还是存在一个基于R的工具集来帮助我解决这个问题?
2 个解决方案
#1
18
You can take screenshots using Selenium:
您可以使用Selenium截取屏幕截图:
library(RSelenium)
rD <- rsDriver(browser = "phantomjs")
remDr <- rD[['client']]
remDr$navigate("http://www.r-project.org")
remDr$screenshot(file = tf <- tempfile(fileext = ".png"))
shell.exec(tf) # on windows
remDr$close()
rD$server$stop()
In earlier versions, you were able to do:
在早期版本中,您可以执行以下操作:
library(RSelenium)
startServer()
remDr <- remoteDriver$new()
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(file = tf <- tempfile(fileext = ".png"))
shell.exec(tf) # on windows
#2
3
I haven't tested it, but this open source project seems to do exactly that: https://github.com/wch/webshot
我还没有测试过,但是这个开源项目似乎正是这样做的:https://github.com/wch/webshot
It is a easy as:
这很简单:
library(webshot)
webshot("https://www.r-project.org/", "r.png")
#1
18
You can take screenshots using Selenium:
您可以使用Selenium截取屏幕截图:
library(RSelenium)
rD <- rsDriver(browser = "phantomjs")
remDr <- rD[['client']]
remDr$navigate("http://www.r-project.org")
remDr$screenshot(file = tf <- tempfile(fileext = ".png"))
shell.exec(tf) # on windows
remDr$close()
rD$server$stop()
In earlier versions, you were able to do:
在早期版本中,您可以执行以下操作:
library(RSelenium)
startServer()
remDr <- remoteDriver$new()
remDr$open()
remDr$navigate("http://www.r-project.org")
remDr$screenshot(file = tf <- tempfile(fileext = ".png"))
shell.exec(tf) # on windows
#2
3
I haven't tested it, but this open source project seems to do exactly that: https://github.com/wch/webshot
我还没有测试过,但是这个开源项目似乎正是这样做的:https://github.com/wch/webshot
It is a easy as:
这很简单:
library(webshot)
webshot("https://www.r-project.org/", "r.png")