How to get the text from td node containg both raw text and a link using Xpath

时间:2016-04-25 09:03:25

标签: xpath

I'm struggling trying to get the text information from a td node containing a link and raw text, as the example bellow.

<td>Statue of <a href="/wiki/Camille_Pelletan" title="Camille Pelletan">Camille Pelletan</a></td>

What is the best Xpath to extract "Statue of Camille Pelletan" together? Thanks!

1 个答案:

答案 0 :(得分:3)

Using the XPath 1.0 string function will return all of the text contained in descendants of the node. (If you pass in a nodeset, it will take only the first node in the set.)

If your example was the entire document, you could use this:

string(//td)

returns:

Statue of Camille Pelletan