page_text() decodes the body to a UTF-8 string, page_json() parses it
with jsonlite::fromJSON(), and page_html() with xml2::read_html().
Usage
page_text(resp, encoding = NULL, check = TRUE)
page_json(resp, ..., check = TRUE)
page_html(resp, encoding = NULL, check = TRUE)Arguments
- resp
A response from
read_page(), or a URL, which is then read withread_page()'s defaults, so thatpage_html(url)stands in forrvest::read_html(url).- encoding
The body's charset, overriding the response's.
- check
Whether an HTTP status outside 200–299 is an error.
- ...
Passed on to
jsonlite::fromJSON().
Value
page_text(): a UTF-8 string. page_json(): what
jsonlite::fromJSON() returns. page_html(): an xml_document whose
relative links resolve against resp$url. Errors are classed under
safeconduct_error: safeconduct_http_error for a status outside
200–299, carrying status and url, and safeconduct_parse_error for
a body that cannot be decoded, or HTML where JSON was asked for.
Details
The charset comes from the response's content-type; without one,
page_text() and page_json() assume UTF-8 and page_html() leaves it
to the page's own <meta charset>. ISO-8859-1 is read as windows-1252, as
browsers do. A body that is not valid in its charset is an error. A "not
found" page served with status 200 passes the status check; page_json()
refuses an HTML body, and for a page, compare resp$url with the URL
asked for.
