0
最初に<span>
を選択し、もう一度<span>
を入力し、そのinnerTextを取得します。 CasperJSで特定の要素を選択する方法は?
Bur私はxpath
またはdocument.querySelector
を使用しようとすると、機能しません。私console.log
私の配列はnullを表示します。
// I want to select first <span>
function getDate() {
var date = document.querySelector('div.movie_intro_info_r li').selectedIndex = 1;
return Array.prototype.map.call(date, function (e) {
return e.innerHTML;
});
};
// I want to select second <span>
function getMovieLength() {
var movieLength = document.querySelectorAll(x('//*[@class="movie_intro_info_r"]/span[2]'));
return Array.prototype.map.call(movieLength, function (e) {
return e.innerText;
});
};
casper.then(function() {
casper.each(movieHref, function (casper, url) {
casper.thenOpen(url, function() {
casper.waitForSelector('div.btn_gray_info.gabtn', function() {
console.log('wait for element');
});
releaseDate[urlCount] = this.evaluate(getDate);
console.log(releaseDate[urlCount]);// show null
movieLength[urlCount] = this.evaluate(getMovieLength);
console.log(movieLength[urlCount]);// show null
urlCount++;
});
});
});
特定の要素を選択してそのinnerTextを取得するにはどうすればよいですか?
おかげでお返事のためのあなたは本当に、私はstackoverflowのからのAPIや他の人のコードを参照してくださいfetchTextあなたのコードのグーグルを試してみてください。私はまだ何も印刷することはできません、私は私の質問にしようとするコードを更新します。あなたは私のコードをチェックして、私はそれをmiisするべきですか?どうもありがとうございました ! –
私はそれが存在するかどうかを確認しようとするかどうか '(this.exists('。movie_intro_info_r> span:nth-of-type(2) ')){ console.log(' yes '); } else { console.log( 'no'); } ' 印刷番号。 –
今は問題ありません。あなたの提案から間違った場所にコードを置くからです。あなたの助け、祝福に感謝します。 –