2017-04-14 1 views
0

PhantomJS를 사용하여 트위터 페이지에서 일부 데이터를 꺼냅니다.특정 요소 이름으로 데이터 스크랩 - 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'); 
});