2017-04-14 6 views
0

私はPhantomJSを使用して、Twitterページからいくつかのデータを取り出しています。ここで私はスクラップしようとしているサンプルコンテンツです:特定の要素名によるデータのスクラップ - PhantomJS

<span class="ProfileTweet-action--reply u-hiddenVisually"> 
    <span class="ProfileTweet-actionCount" data-tweet-stat-count="541"> 
    <span class="ProfileTweet-actionCountForAria" data-aria-label-part>541 replies .</span> 
    </span> 
</span> 

これは回答がカウント取得するための私のコードです:

var replyCount = page.evaluate(function(){ 
return document.getElementsByClassName("ProfileTweet-action--reply"); 
}); 
for (var i = 0; i < replyCount.length; i++) { 
    var replyInt = replyCount[i].innerText; 
    console.log(replyInt); 
} 

出力は541 replies

あるスクラップにする方法がありますdata-tweet-stat-countの値なので、私は "541"を得ることができますか?

他の要素も同じページにあるdata-tweet-stat-countという名前です。誰も私にこれを導くことができますか?

答えて

1
var replyCount = page.evaluate(function(){ 
    return document.querySelector('span.ProfileTweet-action--reply span.ProfileTweet-actionCount').getAttribute('data-tweet-stat-count'); 
});