私はこれまでのところ非常に簡単な例を持っていますが、基本的にはウェブサイトからロゴへのパスを動的にリッピングしようとしています。node.jsのjsdom/jqueryを使用して複数のノードに一致するセレクタを使用するにはどうすればよいですか?
console.log($("#logo img, #links a img", context).attr('src'))
その後、返します:私はセレクタを展開するまで
var sys = require("sys"),
request = require("request"),
$ = require("jquery"),
uri = 'http://www.stevelacey.net';
request({uri:uri}, function (error, response, context) {
if (!error && response.statusCode == 200) {
console.log($("#logo img", context).attr('src'))
}
})
これは正常に動作セレクタは複数の要素と一致するため、
Object [ jsdom NodeList ]: contains 5 items has no method 'indexOf'
を明らかに。これは、この方法を選択しようとするとすぐに起こります。結果を誤って使用しようとしても、つまりNodeListにattrを設定しようとしても起こりません。いずれにしても、jQueryはこれをブラウザで正常に処理します。
私の質問は、これはjsdomの制限ですか、これを回避する方法はありますか?
var this_index = smallest_common_ancestor.childNodes.indexOf(this)
var other_index = smallest_common_ancestor.childNodes.indexOf(otherNode)
ライン114
にjsdom/level3/core.js
中に:
var this_index = smallest_common_ancestor._childArray.indexOf(this)
var other_index = smallest_common_ancestor._childArray.indexOf(otherNode)
正常終了 "画像/ header.pngを"(I
。 – Steve