R 的網頁爬蟲
Timo Grossenbacher
Instructor
//div/p[@class = "blue"](等同 div > p.blue)class 為 special 的 a 節點之 div 元素
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
/ 或 //span、a 等 HTML 類型[...]//span/a[@class = "external"](CSS:span > a.external) //*[@id = "special"]//div(CSS:#special div 或 *#special div)R 的網頁爬蟲