我正在尝试将Selenium的屏幕截图存储到变量中,以便我可以计算出它的高度:
library(RSelenium)
library(magick)
server <- remoteDriver(remoteServerAddr = "localhost",
port = 4444,
browserName = "firefox")
server$open()
server$navigate("https://google.com")
screenshot <- server$screenshot(display = FALSE)
image_info(screenshot)
错误:'image'参数不是magick图像对象。
奇怪的是,如果我将server $ screenshot输出到一个文件并将其加载回来:
,这是有效的server$screenshot(display = FALSE, file"/home/person/img.png")
blankPNG <- image_read("/home/person/img.png")
我know服务器$ screenshot返回“base64编码的PNG”,但我怎么能这样读? print(screenshot)
返回一个字符串。
答案 0 :(得分:2)
终于找到了它:
library('base64enc')
# this returns a list of base64 characters
screenshot <- server$screenshot(display = FALSE)
# converts the base64 characters into a vector
screenshot <- base64decode(toString(screenshot), output = NULL)
# reads the vector as stores it as a PNG
screenshot <- image_read(screenshot)