Can I use the> operator in the KRL () query selector?

I want to get a nested DIV tag using a KRL () request, but it complains about

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

Here's an HTML snippet (there are several in the file):

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

Here is 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 bind multiple query () queries to get a DIV?

+4
source share
2 answers

"div.recent-transfer>div" is a valid request. KNS encountered a problem causing intermittent failures.

Here's how the function is used, so the returned array does not pose a problem:

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

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

I do not know if you have the same problem. But here is a sample rule 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; } } 
+3
source

Source: https://habr.com/ru/post/1345339/


All Articles