krl
2011-03-26 59 views 4 likes 
4

我想用KRL查詢()來得到一個嵌套的DIV標籤,但它抱怨與我可以在KRL查詢()選擇器中使用>運算符嗎?

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嗎?

+4

原庫不支持「>」(子)運算符。最近推出了具有更新庫的新服務器(應該也支持'+'btw)。 必須將更新的庫推送到所有服務器 - 可能在今天晚些時候,也許明天早上。 – MEH 2011-03-29 19:37:50

+0

'@ MEH'您的評論將更適合作爲答案,因爲它畢竟是答案。 – Alex 2011-03-30 03:33:17

回答

3

"div.recent-transfer>div"是一個有效的查詢。 KNS出現問題導致間歇性故障。

這裏的功能如何使用,使得返回數組並不能使問題:

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

當我試圖重現您的問題時,我沒有得到相同的錯誤。相反,我會得到一個「NOT_FOUND_ERR:DOM異常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; 
    } 
} 
+0

+1,我也在我自己的測試中得到了相同的結果。 – Alex 2011-03-27 06:11:33

+0

// 2011/03/28 07:21:09 ERROR Rules.pm a421x42 xfers規則集a421x42失敗:html.query錯誤 - 無效規範「> div」在查詢中:div.recent-transfer> div – 2011-03-28 13:22:44

+1

似乎工作大約一半時間。嘗試http://www.waahui.com/kalculator,刷新頁面將重新運行應用程序。 – 2011-03-28 13:24:29

相關問題