webshot {webshot2} | R Documentation |
Take a screenshot of a URL
Description
Take a screenshot of a URL
Usage
webshot(
url = NULL,
file = "webshot.png",
vwidth = 992,
vheight = 744,
selector = NULL,
cliprect = NULL,
expand = NULL,
delay = 0.2,
zoom = 1,
useragent = NULL,
max_concurrent = getOption("webshot.concurrent", default = 6),
quiet = getOption("webshot.quiet", default = FALSE)
)
Arguments
url |
A vector of URLs to visit. If multiple URLs are provided, it will load and take screenshots of those web pages in parallel. |
file |
A vector of names of output files. Should end with an image file
type ( |
vwidth |
Viewport width. This is the width of the browser "window". |
vheight |
Viewport height This is the height of the browser "window". |
selector |
One or more CSS selectors specifying a DOM element to set the
clipping rectangle to. The screenshot will contain these DOM elements. For
a given selector, if it has more than one match, all matching elements will
be used. This option is not compatible with |
cliprect |
Clipping rectangle. If |
expand |
A numeric vector specifying how many pixels to expand the
clipping rectangle by. If one number, the rectangle will be expanded by
that many pixels on all sides. If four numbers, they specify the top,
right, bottom, and left, in that order. When taking screenshots of multiple
URLs, this parameter can also be a list with same length as |
delay |
Time to wait before taking screenshot, in seconds. Sometimes a longer delay is needed for all assets to display properly. |
zoom |
A number specifying the zoom factor. A zoom factor of 2 will result in twice as many pixels vertically and horizontally. Note that using 2 is not exactly the same as taking a screenshot on a HiDPI (Retina) device: it is like increasing the zoom to 200 doubling the height and width of the browser window. This differs from using a HiDPI device because some web pages load different, higher-resolution images when they know they will be displayed on a HiDPI device (but using zoom will not report that there is a HiDPI device). |
useragent |
The User-Agent header used to request the URL. |
max_concurrent |
(Currently not implemented) |
quiet |
If 'TRUE', status updates via console messages are suppressed. |
Value
Invisibly returns the normalized path to all screenshots taken. The character vector will have a class of '"webshot"'.
Examples
if (interactive()) {
# Whole web page
webshot("https://github.com/rstudio/shiny")
# Might need a delay for all assets to display
webshot("http://rstudio.github.io/leaflet", delay = 0.5)
# One can also take screenshots of several URLs with only one command.
# This is more efficient than calling 'webshot' multiple times.
webshot(c("https://github.com/rstudio/shiny",
"http://rstudio.github.io/leaflet"),
delay = 0.5)
# Clip to the viewport
webshot("http://rstudio.github.io/leaflet", "leaflet-viewport.png",
cliprect = "viewport")
# Specific size
webshot("https://www.r-project.org", vwidth = 1600, vheight = 900,
cliprect = "viewport")
# Manual clipping rectangle
webshot("http://rstudio.github.io/leaflet", "leaflet-clip.png",
cliprect = c(200, 5, 400, 300))
# Using CSS selectors to pick out regions
webshot("http://rstudio.github.io/leaflet", "leaflet-menu.png", selector = ".list-group")
# With multiple selectors, the screenshot will contain all selected elements
webshot("http://reddit.com/", "reddit-top.png",
selector = c("[aria-label='Home']", "input[type='search']"))
# Expand selection region
webshot("http://rstudio.github.io/leaflet", "leaflet-boxes.png",
selector = "#installation", expand = c(10, 50, 0, 50))
# If multiple matches for a given selector, it will take a screenshot that
# contains all matching elements.
webshot("http://rstudio.github.io/leaflet", "leaflet-p.png", selector = "p")
webshot("https://github.com/rstudio/shiny/", "shiny-stats.png",
selector = "ul.numbers-summary")
# Result can be piped to other commands like resize() and shrink()
webshot("https://www.r-project.org/", "r-small.png") %>%
resize("75%") %>%
shrink()
}