我可以使用 > KRL query() 选择器中的运算符?

发布于 2024-10-26 04:29:34 字数 741 浏览 3 评论 0原文

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

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

Here's the HTMLfragment (文件中有多个):

<div class='recent-transfer'>
    <span>...</span>
    <div> <!-- * * * -->
        <div>...</div>
        <div>...</div>
    </div>
</div>

Here's my function:

recent = function() {
    t = http:get(the_url).pick("$..content");
    t.query("div.recent-transfer>div")
}

I Want to select the DIV MARKED * * *。我是否需要链接多个 query() 语句才能获取 DIV?

I want to get a nested DIV tag using KRL query() but it complains with

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

Here's the HTML fragment (there are multiple in the file):

<div class='recent-transfer'>
    <span>...</span>
    <div> <!-- * * * -->
        <div>...</div>
        <div>...</div>
    </div>
</div>

Here's my function:

recent = function() {
    t = http:get(the_url).pick("$..content");
    t.query("div.recent-transfer>div")
}

I want to select the DIV marked * * *. Do I need to chain several query() statements to get the DIV?

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

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

发布评论

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

评论(2

穿越时光隧道 2024-11-02 04:29:35

当我尝试重现您的问题时,我没有收到相同的错误。相反,我会得到“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;
  }
}

When I tried to reproduce your problem, I didn't get the same error. Instead, I would get a "NOT_FOUND_ERR: DOM Exception 8". In my case, it wasn't a problem with the selector at all; it was the fact that the return value of t.query was an array. If I wanted to use that in, say, a notify(), I had to get the 0th element out of the array and return that instead.

I don't know if that is the same problem you are having. But here's a sample ruleset that works for me:

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;
  }
}
梅倚清风 2024-11-02 04:29:35

"div.recent-transfer>div" 是一个有效的查询。 KNS 出现问题,导致间歇性故障。

以下是该函数的使用方式,这样返回的数组就不会出现问题:

rule add_content {
    select when pageview ".*"
    foreach recent() setting (item) {
        append("div#main", item);
    }
}

"div.recent-transfer>div" is a valid query. There was a problem in the KNS causing intermittent failures.

Here's how the function is used, such that the returned array doesn't make problems:

rule add_content {
    select when pageview ".*"
    foreach recent() setting (item) {
        append("div#main", item);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文