How to get node value / innerHTML with XPath?

Tomasz Smykowski picture Tomasz Smykowski · Jun 5, 2012 · Viewed 79.4k times · Source

I have a XPath to select to a class I want: //div[@class='myclass']. But it returns me the whole div (with the <div class='myclass'> also, but I would like to return only the contents of this tag without the tag itself. How can I do it?

Answer

Nikola Bogdanović picture Nikola Bogdanović · Jun 5, 2012
node() = innerXml

text() = innerText

both are arrays, so text()[1] is a first children text node...