| read_page | R Documentation |
fetch() 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.
read_page(
url,
session = NULL,
quiet = FALSE,
timeout = 120,
headed = "auto",
useragent = TRUE
)
url |
The file's URL. |
session |
A |
quiet |
Suppress progress messages. |
timeout |
Seconds a read in the browser may take. |
headed |
How to run the browser when one is needed. |
useragent |
The browser's user-agent string. |
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(). For the errors raised,
see "Errors" below.
Every error raised here is of class safeconduct_error, and one of the
classes below. They are a stable interface: a calling package can catch
them to fall back, to a manual download or a message of its own, without
matching the message text, which may change.
safeconduct_unavailable: no browser can be opened here. No Chrome or
Chromium was found, options(safeconduct.browser = FALSE) is set,
Chrome would not start, or a browser_session() passed in has been
closed. browser_available() says beforehand whether a browser can be
opened, and browser_advice() gives a line to show the person when it
cannot.
safeconduct_not_passed: a browser was opened but did not get
through. Its reason field is "timeout" when the check was not passed
in time and "blocked" when the server blocks the browser too.
safeconduct_download_error: the browser got through, but the transfer
or the read failed.
For example:
tryCatch(
fetch(url, destfile),
safeconduct_unavailable = function(e) message(browser_advice()),
safeconduct_not_passed = function(e) message("Download it by hand from ", url))
A host behind Cloudflare judges the address a request comes from, not
only the browser: every request from the same address counts, the
browser's and the caller's own alike. After a burst of requests – some
forty ranged requests in parallel to one host, in one case – the host
may tighten its check for the address, so that a headless browser which
got through a minute ago times out, or a window wants a click it did not
need before. Keep plain requests to such a host to one or two at a time,
make several reads through one browser_session() rather than a browser
each, and when a check is not passed, try again in a while, or with
headed = TRUE so that a person can click it.
## Not run:
r <- read_page("https://results.vancouver.ca/data/arearesults.json")
page_json(r)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.