Rで学ぶWebスクレイピング
Timo Grossenbacher
Instructor
//div/p[@class = "blue"]、div > p.blue と同等)a に special クラスを含む 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で学ぶWebスクレイピング