gpt4 book ai didi

krl - 我可以在 KRL query() 选择器中使用 > 运算符吗?

转载 作者:行者123 更新时间:2023-12-05 00:38:35 24 4
gpt4 key购买 nike

我想使用 KRL query() 获取嵌套的 DIV 标签,但它提示

ERROR Rules.pm a8x40 show_xfers Ruleset a8x40 failed: html.query error - Invalid specification ">div" in query: div.recent-transfer>div 

这是 HTML 片段(文件中有多个):
<div class='recent-transfer'>
<span>...</span>
<div> <!-- * * * -->
<div>...</div>
<div>...</div>
</div>
</div>

这是我的功能:
recent = function() {
t = http:get(the_url).pick("$..content");
t.query("div.recent-transfer>div")
}

我想选择标记为 * * * 的 DIV .我是否需要链接多个 query() 语句来获取 DIV?

最佳答案

当我试图重现您的问题时,我没有遇到同样的错误。相反,我会得到一个“NOT_FOUND_ERR:DOM Exception 8”。就我而言,选择器根本没有问题;事实是t.query的返回值是一个数组。如果我想在 notify() 中使用它,我必须从数组中取出第 0 个元素并返回它。

不知道你遇到的是不是同样的问题。但这里有一个对我有用的示例规则集:

ruleset a163x61 {
meta {
name "Selector test"
description <<
Testing the query() function
>>
author "Steve Nay"
logging on
}

dispatch {
}

global {
the_url = "http://students.cs.byu.edu/~snay2/content.html";

recent = function() {
t = http:get(the_url).pick("$..content");
// This produces an array.
text = t.query("div.recent-transfer>div");
// We want the text out of the element. Get the first element.
text[0];
// This won't work; throws a "NOT_FOUND_ERR: DOM Exception 8"
//text;
};
}

rule first_rule {
select when pageview ".*" setting ()
pre {
disp = recent();
}
notify("Content:", disp) with sticky=true;
}
}

关于krl - 我可以在 KRL query() 选择器中使用 > 运算符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5442892/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com