
Read a page or a feed into memory, through a browser if the server insists
Source:R/fetch.R
read_page.Rdfetch() for a page or a feed: the response is returned rather than
written to disk, shaped like curl::curl_fetch_memory()'s, by the same
route; where only the browser is served, the page the browser holds on
the host reads it. For a feed read every few minutes, pass a
browser_session() instead of opening a browser per call; a check the
host asks for again meanwhile is passed and the read repeated.
Usage
read_page(
url,
session = NULL,
quiet = FALSE,
timeout = 120,
headed = "auto",
useragent = TRUE
)Arguments
- url
The file's URL.
- session
A
browser_session()on the host. The page is then read in that browser without probing.- quiet
Suppress progress messages.
- timeout
Seconds a read in the browser may take.
- headed
How to run the browser when one is needed.
"auto", the default, runs headless and opens a window only when the headless run ends on a check or a block and there is a display to show it on;TRUEopens a window at once;FALSEnever does. A second check, at the file's URL, takes headless Chrome about two minutes to pass unclicked, where a window is through as soon as its box is clicked:"auto"waits those minutes before opening a window,TRUEskips the wait.- useragent
The browser's user-agent string.
TRUE, the default, drops the wordHeadlessfrom Chrome's own string, which some hosts refuse on that word alone, and changes nothing else;NULLleaves Chrome's own; a string is used as given.
Value
A list: url (after redirects), status_code, type (the
content-type, lower case), headers (a named list) and content
(raw). An HTTP error status is returned, not raised. Parse it with
page_text(), page_json() or page_html(). Errors as fetch()'s.
Examples
if (FALSE) { # \dontrun{
r <- read_page("https://results.vancouver.ca/data/arearesults.json")
page_json(r)
} # }