Rilcon42 Rilcon42 - 7 months ago 57
HTML Question

finding correct xpath for a table without an id

I am following a tutorial on R-Bloggers using rvest to scrape table. I think I have the wrong column id value, but I don't understand how to get the correct one. Can someone explain what value I should use, and why?

interest<-url("")%>%read_html()%>%html_nodes(xpath='//*[@id="column0"]/table[1]') %>% html_table()

The structure returns is an empty list.


For me it is usual a trial and error to find the correct table. In this case, the third table is what you are looking for:

tables<-html_nodes(page, "table") 

Instead of using the xpath, I just parse out the "table" tag and looked at each table to locate the correct one. The piping command is handy but it makes it harder to debug when something goes wrong.