XPath子弦在Firefox Web检查员/控制台中是否有效?

发布于 2025-02-09 11:30:29 字数 464 浏览 0 评论 0原文

此XPath返回一个百分比(例如16%):

//div/div/div[@class='underlay']/strong

我只想提取数字“ rel =“ nofollow noreferrer”> substring

substring (//div/div/div[@class='underlay']/strong, 1, 2)

但它只是返回错误消息。

这应该是可行的吗?

根据语法上方的链接上的文档是substring(字符串,start,length)

。还有其他方法可以获取数字(16)吗?

谢谢。


更新:我在Web Inspector的搜索字段以及使用$ x(“ //*”)中使用了它

This Xpath returns a percentage (e.g, 16%):

//div/div/div[@class='underlay']/strong

I want to extract just the digits so I tried substring

substring (//div/div/div[@class='underlay']/strong, 1, 2)

but it just returns an error message.

Is this supposed to work?

According to the documentation on the link above the syntax is substring(string, start, length) and it is supported by Gecko.

Are there any other way to just get the digits (16)?

Thank you.


Update: I used it in the web inspector's search field as well as in the console using $x("//*")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2025-02-16 11:30:30

我刚刚在此页面上打开了Firefox的Inspector面板,并在控制台中评估了以下内容:

document.evaluate("substring(//div[@itemprop='text']/p[1], 39, 2)", document).stringValue

结果是字符串“ 16”。因此,我认为我们可以说它绝对可以起作用。

I just opened Firefox's inspector panel on this very page and evaluated the following in the console:

document.evaluate("substring(//div[@itemprop='text']/p[1], 39, 2)", document).stringValue

The result was the string "16". So I think we can say that it should definitely work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文