在 xpath 中使用 YQL 和 substring-before
我正在尝试使用 xpath 在 html 页面中的一个段落中获取“--”之前的字符串并将其发送到 yql,
例如我想从以下文章中获取日期:
<div> <p>Date --- the body of the article</p> </div>
我在 yql 中尝试了此查询:
select * from html where url="article url" and xpath="//div/p/text()/[substring-before(.,'--')]"
但确实如此不工作。
如何获取“--”之前的文章日期
I am trying to get a string before '--' within a paragraph in an html page using the xpath and send it to yql
for example i want to get the date from the following article:
<div> <p>Date --- the body of the article</p> </div>
I tried this query in yql:
select * from html where url="article url" and xpath="//div/p/text()/[substring-before(.,'--')]"
but it does not work.
how can I get the date of the article which is before the '--'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地使用:
You can simply use:
使用:
此 XPath 表达式的计算结果为紧邻 XML 文档中第一个文本节点中
'--'
之前的字符串,该节点是p< 的子节点。 /code> 是
div
顶部元素的子元素。如果您想要为每个此类文本节点获取此值,则必须使用如下表达式:
并计算此表达式
$N
次,对于$k = 1,2, ..., $N
其中
$N
是count(//div/p/text())
请注意:尽量避免使用
//
XPath 伪运算符总是当 XML 文档的结构静态已知时。使用//
通常会导致效率低下 (O(N^2)),这对于大型 XML 文档来说尤其痛苦。Use:
This XPath expression evaluates to the string immediately preceding
'--'
in the first text node in the XML document, that is a child of ap
that is a child of thediv
top element.In case you want to get this value for every such text node, you have to use an expression like:
and evaluate this expression
$N
times, for$k = 1,2, ..., $N
where
$N
iscount(//div/p/text())
Do note: Try to avoid using the
//
XPath pseudo-operator always when the structure of the XML document is statically known. Using//
usually results in big inefficiency (O(N^2)) that are felt especially painful on big XML documents.