Introdução ao HTML

Web Scraping em R

Timo Grossenbacher

Instructor

Se você vê algo, dá para fazer scraping

sem download

Web Scraping em R

Hypertext Markup Language (HTML)

<html> 
  <body> 
    <h2>Um primeiro exemplo</h2>
    <p>Um parágrafo de texto.</p>
    <p>
      A seguir, uma lista:
    </p>
  </body> 
</html>

Introdução ao HTML

Web Scraping em R

HTML é organizado de forma hierárquica

Introdução ao HTML

...
    <div>
      A seguir, uma lista:
      <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
      </ul>
    </div>
...
Web Scraping em R

Tags HTML podem ter atributos

Introdução ao HTML

...
    <p>
      A seguir, um 
      <a href="https://google.com">link</a>.
    </p>
...
Web Scraping em R

Lendo HTML com R

library(rvest)
html <- read_html(html_document)
html
{html_document}
<html>
[1] <body> \n    <h2>Um primeiro exemplo</h2>\n    <p>Um parágrafo de texto.</p>\n   ...
class(html)
"xml_document" "xml_node"
Web Scraping em R
library(xml2)
xml_structure(html)
<html>
  <body>
    {text}
    <h2>
      {text}
    {text}
    <p>
      {text}
    {text}
    <p>
      {text}
      <a [href]>
        {text}
      {text}
    {text}
Web Scraping em R

Vamos analisar HTML!

Web Scraping em R

Preparing Video For Download...