0

I'm wanting to parse the html to pull out specific pieces using xpathSApply but the xmlRoot call returns an element whose name is the text of the entire document:

> url <- "http://www.achaea.com/game/who"
> doc <- htmlParse(url)
> top <- xmlRoot(doc)
> xmlName(top)

Which displays the entire HTML document for the 'name' rather than a root element name. Can someone tell me what is the cause of this behavior? I want to be able to pull out the individual names in the 'honors' hrefs.

3
  • Thanks Randy, you are right, I exited RStudio and started it back up and got your results. This looks like I had some sort of interaction with previously executed code. I should have used rm on doc to have a clean slate. This resolves my problem. Commented Apr 13, 2014 at 1:52
  • I thought I misunderstood your question and removed the comment...anyway, see if my answer produces what you want. Commented Apr 13, 2014 at 1:54
  • Please consider removing the question since it was not a problem. Commented Apr 13, 2014 at 1:55

1 Answer 1

1

Try

xpathSApply(top, "//div[@id='content']//a", xmlValue)

If you want to links

xpathSApply(top, "//div[@id='content']//a", xmlAttrs, "href")
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.