phantomjs casperjs와 spooky를 사용하여 무한 스크롤을 사용하는 페이지를 긁어 내려고했습니다. 더 많은 버튼을 계속 클릭하고 새 링크를 수동으로 중지 할 때까지 결과에서 가져 오는 것으로되어 있습니다. 그러나 스크립트는 충돌 할 때까지 점점 더 많은 메모리를 사용하기 시작합니다. 나는 또한 무한 스크롤 사이트에서이 문제로 실행했습니다phantomjs/casperjs/spookyjs 메모리 사용량을 줄일 수 있습니다.
function pressMore(previousLinksLength) {
this.click('#projects > div.container-flex.px2 > div > a');
this.wait(1000, function() {
links = this.evaluate(function() {
var projectPreview = document.querySelectorAll('.project-thumbnail a');
return Array.prototype.map.call(projectPreview, function(e) {
return e.getAttribute('href');
});
});
this.emit('sendScrapedLinks', links.slice(previousLinksLength));
// repeat scrape function
pressMore.call(this, links.length);
});
}
// spookyjs starts here
spooky.start(scrapingUrl);
//press the more button
spooky.then(pressMore);
spooky.run();
'sendScrapedLinks' 이벤트 핸들러는 얼마나 복잡한가요? 그 외에는 더 나은 것을 할 수 없습니다. –
그냥 간단한 mongoose.save() 함수입니다. – Bunker