0

I tried to parse XMLInternalElementNode to data frame. I have read How to parse XML to R data frame and How to get table data from html table in xml but none of the solutions work for my case.

My code below does not give me a table:

    web=getURL("http://www.tocom.or.jp/market/kobetu/rubber.html", header=FALSE, httpheader = c(Accept="text/html"), verbose = TRUE)
    doc=htmlParse(web, asText=TRUE, encoding="Windows-1252")
    tableNodes = getNodeSet(doc, "//table")

    #this gives me error
    xmlParse(tableNodes[[2]])
    Error in as.vector(x, "character") : 
    cannot coerce type 'externalptr' to vector of type 'character'

    #This does not return me the table neither:
    xpathSApply(tableNodes[[2]], path = '//table//tr')

So how should I retrieve the table from this website?

Community
  • 1
  • 1
  • 1
    You already have all the tables after the call to `tableNodes = getNodeSet(doc, "//table")`. But, even after that, it seems `readHTMLTable()` can't parse these for some reason, so you should try and use @Floo0's answer. – hrbrmstr Sep 27 '16 at 11:55

1 Answers1

2

What about:

library(rvest)
doc <- read_html("http://www.tocom.or.jp/market/kobetu/rubber.html")
doc %>% html_table(fill=TRUE)

Which gives you a list of all tables.

Rentrop
  • 20,979
  • 10
  • 72
  • 100