0

I am trying to get the Xpath of the following. I am trying to get the name of the location. 'London' from this div tag. I use \h4\a as Xpath but i am unable to do so. Any suggestions on how to specify correct Xpath?

 <h4><a href="www.example.com" tile="Click here">London</a></h4>
4
  • maybe, this will //h4/a ? :) Commented Aug 1, 2015 at 23:29
  • Are you using a specific language? Commented Aug 1, 2015 at 23:32
  • i am using R and it has functionality for xpath. Commented Aug 1, 2015 at 23:35
  • here is the code plain.text <- xpathSApply(doc, "//h4/a", xmlValue) Commented Aug 1, 2015 at 23:36

1 Answer 1

1

You can use the XML package, applying XPath to grab the text from that node.

library(XML)
res <- xpathSApply(htmlParse(doc), '//h4/a', xmlValue)

Or the shorthand version:

res <- doc['//h4/a/text()'][[1]]
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.