Web Scraping in R
Timo Grossenbacher
Instructor
//div/p[@class = "blue"] (equivalent to div > p.blue)div elements that contain a nodes with a special class
html %>%
html_elements(xpath = '//p')
# CSS selector equivalent: p
html %>%
html_elements(xpath = '//body//p')
# CSS selector equivalent: body p
html %>%
html_elements(xpath = '/html/body//p')
# CSS selector equivalent: html > body p

html %>%
html_elements(xpath = '//div/p')
# CSS selector equivalent: div > p

html %>%
html_elements(xpath = '//div[a]')
# CSS selector equivalent: none
/ or //span and a[...]//span/a[@class = "external"] (CSS: span > a.external) //*[@id = "special"]//div (CSS: #special div or *#special div)Web Scraping in R