r - Subscript out of bounds error when scrapping using an xpath with the rvest package -
i attempting scrape table website using rvest
package:
library("rvest") uci_html <- read_html("http://archive.ics.uci.edu/ml/datasets.html") uci_data <- uci_html %>% html_nodes(xpath="/html/body/table[2]/tbody/tr/td[2]/table[2]") %>% html_table() uci_data <- uci_data[[1]]
as far examples have seen, format using should work, r
not scrapping data , result getting error:
error in uci_data[[1]] : subscript out of bounds
do know why might case , can scrape data?
i don't quite understand looks tbody unnecessary.
library("rvest") uci_html <- read_html("http://archive.ics.uci.edu/ml/datasets.html") uci_data <- uci_html %>% html_nodes(xpath="/html/body/table[2]/tr/td[2]/table[2]") %>% html_table( fill=true) uci_data <- uci_data[[1]]
another way using html tags is:
tables<-uci_html %>% html_nodes("table") html_table(tables[6], fill=true)[[1]]
in order identify sixth table table of interest, involve trial , error find using html tags easier xpath form.
the code without xpath is amazing! thanks
ReplyDelete