我正在試驗rvest
學習網絡抓取R.我試圖複製樂高榜樣的頁面的其他幾節,並使用selector gadget
id。網站抓取與R和rvest
我從R Studio tutorial拉下了這個例子。用下面的代碼,1和2工作,但3不工作。
library(rvest)
lego_movie <- html("http://www.imdb.com/title/tt1490017/")
# 1 - Get rating
lego_movie %>%
html_node("strong span") %>%
html_text() %>%
as.numeric()
# 2 - Grab actor names
lego_movie %>%
html_nodes("#titleCast .itemprop span") %>%
html_text()
# 3 - Get Meta Score
lego_movie %>%
html_node(".star-box-details a:nth-child(4)") %>%
html_text() %>%
as.numeric()