使用 XPath 查找变量时,仅获取该变量的一部分

发布于 2024-07-13 18:48:49 字数 225 浏览 4 评论 0原文

我是 XPath 新手。 我正在编写一个代码来从页面中获取所有 3 位数字。 它们不是恒定的,在 105、515 和 320 之间变化。我希望两个能够将这些数字标记为两个单独的部分...

我希望能够抓住一个 X 路径表达式中的第一个数字 和 在进行研究时,我发现第二个 X 路径表达式中的后两位数字

无法用“零值”进行标记,但是有什么方法可以做到这一点吗?

谢谢

I am new to XPath. I am writing a code to grab all the 3 digit numbers from a page. They are not constant, varying between 105, 515, and 320. I want two be able to tokenize these numbers into two separate pieces...

i would love to be able to grab the first digit in one X-path expression
and
the second two digits in a second X-Path expression

on doing my research I came across that you couldn't tokenize with 'zero value,' but is there any way to do this?

Thanks

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

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

发布评论

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

评论(1

刘备忘录 2024-07-20 18:48:49

在我看来,问题实际上是关于将 3 位数字拆分为两个字符串的可能方法,第一个包含第一个数字,第二个包含剩余的数字两位数。

这里是一个可能的解决方案

以下 XPath 表达式在计算时会生成一个包含数字 $vNum 的第一位数字的字符串(在实际的 XPath 表达式中,将 $vNum 替换为生成此值的 XPath 表达式):

  substring($vNum, 1, 1)

以下 XPath 表达式在求值时会生成一个包含 3 位数字 $vNum 的最后两位数字的字符串(在实际的 XPath 表达式中,将 $vNum 替换为 XPath生成此值的表达式):

  substring($vNum, 2)

如果我们不确定 $vNum 的位数下面的 XPath 表达式在求值时会生成一个字符串,其中包含紧跟在 $vNum 后面的两位数字3 位以上数字的第一位数字 $vNum(在实际的 XPath 表达式中,用生成此值的 XPath 表达式替换 $vNum):

  substring($vNum, 2, 2)

最后,如果我们再次不知道确切的数字位数,但想要获取其中的最后两位,以下 XPath 表达式在计算时会生成一个字符串,其中包含 2+ 位数字 $vNum 末尾的两位数字(在实际的 XPath 表达式中,替换 $ vNum 以及生成该值的 XPath 表达式):

 substring($vNum, string-length($vNum) - 1)

It seems to me that the question is actually about the possible ways to split a 3-digit number into two strings, the first containing the first digit and the second containing the remaining two digits.

Here is one possible solution:

The following XPath expression when evaluated produces a string containing the first digit of a number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 1, 1)

The following XPath expression when evaluated produces a string containing the last two digits of a 3-digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 2)

In case if we are not sure about the number of digits $vNum has, the following XPath expression when evaluated produces a string containing the two digits that immediately follow the first digit of a 3+ digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

  substring($vNum, 2, 2)

And lastly, if we again don't know the exact number of digits, but want to get the last two of them, the following XPath expression when evaluated produces a string containing the two digits at the end of a 2+ digit number $vNum (in an actual XPath expression, substitute $vNum with the XPath expression that produces this value):

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