EVOLUTION-MANAGER
Edit File: read_xml.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Read HTML or XML.</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for read_xml {xml2}"><tr><td>read_xml {xml2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Read HTML or XML.</h2> <h3>Description</h3> <p>Read HTML or XML. </p> <h3>Usage</h3> <pre> read_xml(x, encoding = "", ..., as_html = FALSE, options = "NOBLANKS") read_html(x, encoding = "", ..., options = c("RECOVER", "NOERROR", "NOBLANKS")) ## S3 method for class 'character' read_xml(x, encoding = "", ..., as_html = FALSE, options = "NOBLANKS") ## S3 method for class 'raw' read_xml( x, encoding = "", base_url = "", ..., as_html = FALSE, options = "NOBLANKS" ) ## S3 method for class 'connection' read_xml( x, encoding = "", n = 64 * 1024, verbose = FALSE, ..., base_url = "", as_html = FALSE, options = "NOBLANKS" ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A string, a connection, or a raw vector. </p> <p>A string can be either a path, a url or literal xml. Urls will be converted into connections either using <code>base::url</code> or, if installed, <code>curl::curl</code>. Local paths ending in <code>.gz</code>, <code>.bz2</code>, <code>.xz</code>, <code>.zip</code> will be automatically uncompressed. </p> <p>If a connection, the complete connection is read into a raw vector before being parsed.</p> </td></tr> <tr valign="top"><td><code>encoding</code></td> <td> <p>Specify a default encoding for the document. Unless otherwise specified XML documents are assumed to be in UTF-8 or UTF-16. If the document is not UTF-8/16, and lacks an explicit encoding directive, this allows you to supply a default.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments passed on to methods.</p> </td></tr> <tr valign="top"><td><code>as_html</code></td> <td> <p>Optionally parse an xml file as if it's html.</p> </td></tr> <tr valign="top"><td><code>options</code></td> <td> <p>Set parsing options for the libxml2 parser. Zero or more of </p> <dl> <dt>RECOVER</dt><dd><p>recover on errors</p> </dd><dt>NOENT</dt><dd><p>substitute entities</p> </dd><dt>DTDLOAD</dt><dd><p>load the external subset</p> </dd><dt>DTDATTR</dt><dd><p>default DTD attributes</p> </dd><dt>DTDVALID</dt><dd><p>validate with the DTD</p> </dd><dt>NOERROR</dt><dd><p>suppress error reports</p> </dd><dt>NOWARNING</dt><dd><p>suppress warning reports</p> </dd><dt>PEDANTIC</dt><dd><p>pedantic error reporting</p> </dd><dt>NOBLANKS</dt><dd><p>remove blank nodes</p> </dd><dt>SAX1</dt><dd><p>use the SAX1 interface internally</p> </dd><dt>XINCLUDE</dt><dd><p>Implement XInclude substitition</p> </dd><dt>NONET</dt><dd><p>Forbid network access</p> </dd><dt>NODICT</dt><dd><p>Do not reuse the context dictionary</p> </dd><dt>NSCLEAN</dt><dd><p>remove redundant namespaces declarations</p> </dd><dt>NOCDATA</dt><dd><p>merge CDATA as text nodes</p> </dd><dt>NOXINCNODE</dt><dd><p>do not generate XINCLUDE START/END nodes</p> </dd><dt>COMPACT</dt><dd><p>compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)</p> </dd><dt>OLD10</dt><dd><p>parse using XML-1.0 before update 5</p> </dd><dt>NOBASEFIX</dt><dd><p>do not fixup XINCLUDE xml:base uris</p> </dd><dt>HUGE</dt><dd><p>relax any hardcoded limit from the parser</p> </dd><dt>OLDSAX</dt><dd><p>parse using SAX2 interface before 2.7.0</p> </dd><dt>IGNORE_ENC</dt><dd><p>ignore internal document encoding hint</p> </dd><dt>BIG_LINES</dt><dd><p>Store big lines numbers in text PSVI field</p> </dd></dl> </td></tr> <tr valign="top"><td><code>base_url</code></td> <td> <p>When loading from a connection, raw vector or literal html/xml, this allows you to specify a base url for the document. Base urls are used to turn relative urls into absolute urls.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>If <code>file</code> is a connection, the number of bytes to read per iteration. Defaults to 64kb.</p> </td></tr> <tr valign="top"><td><code>verbose</code></td> <td> <p>When reading from a slow connection, this prints some output on every iteration so you know its working.</p> </td></tr> </table> <h3>Value</h3> <p>An XML document. HTML is normalised to valid XML - this may not be exactly the same transformation performed by the browser, but it's a reasonable approximation. </p> <h3>Setting the "user agent" header</h3> <p>When performing web scraping tasks it is both good practice — and often required — to set the <a href="https://en.wikipedia.org/wiki/User_agent">user agent</a> request header to a specific value. Sometimes this value is assigned to emulate a browser in order to have content render in a certain way (e.g. <code style="white-space: pre;">Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0</code> to emulate more recent Windows browsers). Most often, this value should be set to provide the web resource owner information on who you are and the intent of your actions like this Google scraping bot user agent identifier: <code style="white-space: pre;">Googlebot/2.1 (+http://www.google.com/bot.html)</code>. </p> <p>You can set the HTTP user agent for URL-based requests using <code><a href="../../httr/html/set_config.html">httr::set_config()</a></code> and <code><a href="../../httr/html/user_agent.html">httr::user_agent()</a></code>: </p> <p><code>httr::set_config(httr::user_agent("me@example.com; +https://example.com/info.html"))</code> </p> <p><code><a href="../../httr/html/set_config.html">httr::set_config()</a></code> changes the configuration globally, <code><a href="../../httr/html/with_config.html">httr::with_config()</a></code> can be used to change configuration temporarily. </p> <h3>Examples</h3> <pre> # Literal xml/html is useful for small examples read_xml("<foo><bar /></foo>") read_html("<html><title>Hi<title></html>") read_html("<html><title>Hi") # From a local path read_html(system.file("extdata", "r-project.html", package = "xml2")) ## Not run: # From a url cd <- read_xml(xml2_example("cd_catalog.xml")) me <- read_html("http://had.co.nz") ## End(Not run) </pre> <hr /><div style="text-align: center;">[Package <em>xml2</em> version 1.3.2 <a href="00Index.html">Index</a>]</div> </body></html>