Introduction to CSS

Web Scraping in R

Timo Grossenbacher

Instructor

Cascading Style Sheets

h1 {
    color: red;
}
p {
    font-style: italic;
}
<html>
  <body>
    <h1>Welcome to Web Scraping!</h1>
    <p>Be it in R, Python or any 
      other language - 
      scraping is fun!</p>
  </body>
</html>
Web Scraping in R

CSS selectors

h1 {
  color: green;
}
p {
  font-style: italic;
}
h1, p {
  font-family: sans-serif;
}
...
    <h1>Another CSS example.</h1>
    <p>Some text.</p>
...

Another CSS example

html %>% html_elements('h1, p')
{xml_nodeset (2)}
[1] <h1> Another CSS ex...
[2] <p>Some text</p>
Web Scraping in R

Type selectors

type {
    key: value;
}

html %>% html_elements('type') # e.g. 'h1' or 'a' or 'span'
type1, type2 {
    key: value;
}

html %>% html_elements('type1, type2')
* {
    key: value;
}

html %>% html_elements('*')
Web Scraping in R

Let's do this!

Web Scraping in R

Preparing Video For Download...