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?

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. Commented Sep 27, 2016 at 11:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.