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.


Comments

Post a Comment

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

javascript - Angular2 intelliJ config error.. Cannot find module '@angular/core' -