如何使用 Xpath 从包含原始文本和链接的 td 节点获取文本 [英] How to get the text from td node containg both raw text and a link using Xpath

查看:31
本文介绍了如何使用 Xpath 从包含原始文本和链接的 td 节点获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力尝试从包含链接和原始文本的 td 节点获取文本信息,如下例所示.

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>

将Camille Pelletan 雕像"一起提取的最佳 Xpath 是什么?谢谢!

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

推荐答案

使用 XPath 1.0 string 函数将返回节点后代中包含的所有文本.(如果你传入一个节点集,它只会获取集合中的第一个节点.)

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)

返回:

卡米尔佩莱坦雕像

这篇关于如何使用 Xpath 从包含原始文本和链接的 td 节点获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆