如何在R中使用RSelenium库缩小页面? [英] How to zoom out page using RSelenium library in R?
问题描述
我正在尝试使用 R 中的 RSelenium 库编写一个网络爬虫.我工作的最后一步包括截取网页上的表格.要将整个表格放入窗口中,我应该缩小网络浏览器(在这种情况下是 firefox).我尝试使用:
I am trying to write a web-scraper using RSelenium Library in R. The last step of my work includes taking screenshot of a table on web page. To fit the whole table into the window I should zoom out the web browser (in that case it's firefox). I tried to use:
webElem <- remDR$findElement("css", "body")
webElem$clickElement()
webElem$sendKeysToElement(list(key = "control", "-"))
然而它不起作用.我也看到了这个线程:在浏览器中默认缩小闪亮的应用程序 并发现有希望的代码片段:图书馆(闪亮)
however it doesn't work. I saw also this thread: Zoom out shiny app at default in browser and found there promising fragment of code: library(shiny)
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
tags$style("
body {
-moz-transform: scale(0.8, 0.8); /* Moz-browsers */
zoom: 0.8; /* Other non-webkit browsers */
zoom: 80%; /* Webkit browsers */
}
"),
我不知道是否可以在 R Selenium 中做类似的事情,以及如何在 RSelenium 中实现 css 缩放修改.我会感谢有 R 经验的人的提示.
I have no idea if it's possible to do something similiar in R Selenium and how to implement css scale modification in RSelenium. Iwould appreciate hints from someone more experienced with R.
推荐答案
事实证明,解决我的问题的好方法是简单地更改 RSelenium 中的分辨率:
It turned out, that good solution to my problem was simple change of resolution in RSelenium:
remDR$setWindowSize(2496, 1404)
它可以很好地满足我目前的目的.
It works fine for my current purpose.
这篇关于如何在R中使用RSelenium库缩小页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!