Xpath expression to select text from link
You tried
//a
?
More specific is better:
//a[@class='bf' and starts-with(@href, '/book/')]
Note that this selects the item <a>
. In a host environment, it is easy to extract the text value of that node using standard DOM methods (like a property .textContent
).
To select the actual text node, see other answers in this thread.
source to share
It also depends on the rest of your document. If you use //
in the beginning, all matching nodes will be returned, which can be too large if you have other links in your document.
Also, the possible xpath expression is //a/text()
.
The tag /a
you tried only returns a
-tag if it's the root element. To get the link text you need to add a part /text()
.
source to share