user3570187
user3570187

Reputation: 1773

Xpath finding in the html code

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>

Upvotes: 0

Views: 61

Answers (1)

hwnd
hwnd

Reputation: 70722

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]]

Upvotes: 1

Related Questions