用于从链接中选择文本的 xpath 表达式 [英] xpath expression to select text from link

查看:27
本文介绍了用于从链接中选择文本的 xpath 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的html文件内容:

I have such content of html file:

<a class="bf" title="Link to book" href="/book/229920/">书名</a>

帮助我构建 xpath 表达式以获取链接文本(书名).我尝试使用 /a,但表达式计算没有结果.

Help me to construct xpath expression to get link text (book name). I try to use /a, but expression evaluates without results.

推荐答案

你试过了吗

//a

?

越具体越好:

//a[@class='bf' and starts-with(@href, '/book/')]

请注意,这将选择 元素.在您的主机环境中,通过标准 DOM 方法(如 .textContent 属性)可以轻松提取该节点的文本值.

Note that this selects the <a> element. In your host environment it's easy to extract the text value of that node via standard DOM methods (like the .textContent property).

要选择实际的文本节点,请参阅此线程中的其他答案.

To select the actual text node, see the other answers in this thread.

这篇关于用于从链接中选择文本的 xpath 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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