4

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を選択したい* * *。DIV を取得するには、複数の query() ステートメントをチェーンする必要がありますか?

4

2 に答える 2

3

"div.recent-transfer>div"有効なクエリです。KNSに問題があり、断続的な障害が発生しました。

返された配列で問題が発生しないように、関数を使用する方法は次のとおりです。

rule add_content {
    select when pageview ".*"
    foreach recent() setting (item) {
        append("div#main", item);
    }
}
于 2011-03-30T16:20:55.463 に答える
3

問題を再現しようとしたところ、同じエラーは発生しませんでした。代わりに、「NOT_FOUND_ERR: DOM Exception 8」が表示されます。私の場合、それはセレクタの問題ではありませんでした。t.queryの戻り値が配列だったという事実でした。たとえば、 a でそれを使用したい場合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;
  }
}
于 2011-03-26T16:40:41.473 に答える