2016-09-14 2 views
0

루프 링크 자신의 웹 사이트/데이터베이스에서 다른 데이터베이스로 긁힘을 허용하지 않습니다. 이것은 동적로드 페이지에서 헤드리스 브라우저 테스트를위한 학업 목적으로 만 사용되었습니다. 데이터를 남용하지 마십시오.캐스퍼는 하나의 자바 스크립트 기반 페이지에 부하가 걸리는 페이지 수를

기본적으로 나는 페이지가 동적으로 자바 스크립트를 통해로드되지만 여러 페이지에서 이미지 링크를 가져 오려고합니다. 그래서 머리가없는 브라우저를 시험해 보았습니다. casperjsphantomjs을 작성했습니다.

내 문제는 getThumbNails()가 동일한 데이터를 두 번 출력하는 함수입니다. 다음은 출력 로그입니다. 첫 번째 '1'과 첫 번째 '2'는 같은 링크입니다. http://looplink.ensemblere.com/SearchResults

내가 사용하는 리눅스에서 떠들썩한 파티를 통해 스크립트를 실행하고 있습니다 :

다음

Casperjs Evaluate Diagram 내가 근근이 살아가고있어 웹 사이트입니다 : 여기

[email protected]:~/WeB$ casperjs --web-security=no --cookies-file=/tmp/mycookies.txt 9Cas.js 
First Page Is Loaded 
Second Page Is Loaded 
1 http://x.lnimg.com/photo/thumb_480/40f175f108f5492b9cdec6486d753f8d.jpg 
1 http://x.lnimg.com/photo/thumb_480/29081ed96a6349a08c27424ce3bd2842.jpg 
1 http://x.lnimg.com/photo/thumb_480/29cd278e7cc34d9782d0a22782af2134.jpg 
1 http://x.lnimg.com/photo/thumb_480/3979dc0f0987407bb9f825f2a0cb3fa9.jpg 
1 http://x.lnimg.com/photo/thumb_480/dd06239abbf1433099ad3278607e5d7f.jpg 
1 http://x.lnimg.com/photo/thumb_480/6e7c6b6076d5414b8ee59baed3dc3131.jpg 
1 http://x.lnimg.com/photo/thumb_480/97027946bbf745a59d44ac1c3e9d22fe.jpg 
1 http://x.lnimg.com/photo/thumb_480/396fd224e85f42aea7a10e1873ed627c.jpg 
1 http://x.lnimg.com/photo/thumb_480/62f6afc3f50942388df9fe66e99a2ab4.jpg 
1 http://x.lnimg.com/photo/thumb_480/09ba5b97da4e47b1a97bac86e125001d.jpg 
1 http://x.lnimg.com/photo/thumb_480/580dcc66cd7f48d8aae8f583cd8e5e4b.jpg 
1 http://x.lnimg.com/photo/thumb_480/e62f6d11449b41ff93e191f6045cb304.jpg 
1 http://x.lnimg.com/photo/thumb_480/596230f07ebf471383991a99bd43420a.jpg 
1 http://x.lnimg.com/photo/thumb_480/da63be695fed4617b594d19e4aa0dc7a.jpg 
1 http://x.lnimg.com/photo/thumb_480/58f28244a2494c868006a97534e694e6.jpg 
1 http://x.lnimg.com/photo/thumb_480/1b0246dfe4314404b32147061198cf80.jpg 
1 http://x.lnimg.com/photo/thumb_480/b10a9bb8252f4d3d9638284f6f68fd6b.jpg 
1 http://x.lnimg.com/photo/thumb_480/48bf185da5f74a369dd629dd183bc8b3.jpg 
1 http://x.lnimg.com/photo/thumb_480/7008392330f847ecb3af7058ce0b2e3b.jpg 
1 http://x.lnimg.com/photo/thumb_480/fcf5618fc7d04265a912cce9f7dec344.jpg 
1 //x.lnimg.com/images/search/map/pinprofileclose2.gif 
1 
1 //x.lnimg.com/images/search/map/pinprofile-ViewDetails.gif 
1 http://ak.t0.tiles.virtualearth.net/tiles/r0?g=5289&mkt=en-us&lbl=l0&stl=h&shading=hill&n=z 
1 http://ak.dynamic.t1.tiles.virtualearth.net/comp/ch/0231?mkt=en-us&it=G,L&shading=hill&og=132&n=z&key=AhfWRPlwZlVGewL9th5vsIklmzvMkUMm8wx6pz5nXzgDlYXliZFSr6lBvgHYCZQj 
2 http://x.lnimg.com/photo/thumb_480/40f175f108f5492b9cdec6486d753f8d.jpg 
2 http://x.lnimg.com/photo/thumb_480/29081ed96a6349a08c27424ce3bd2842.jpg 
2 http://x.lnimg.com/photo/thumb_480/29cd278e7cc34d9782d0a22782af2134.jpg 
2 http://x.lnimg.com/photo/thumb_480/3979dc0f0987407bb9f825f2a0cb3fa9.jpg 
2 http://x.lnimg.com/photo/thumb_480/dd06239abbf1433099ad3278607e5d7f.jpg 
2 http://x.lnimg.com/photo/thumb_480/6e7c6b6076d5414b8ee59baed3dc3131.jpg 
2 http://x.lnimg.com/photo/thumb_480/97027946bbf745a59d44ac1c3e9d22fe.jpg 
2 http://x.lnimg.com/photo/thumb_480/396fd224e85f42aea7a10e1873ed627c.jpg 
2 http://x.lnimg.com/photo/thumb_480/62f6afc3f50942388df9fe66e99a2ab4.jpg 
2 http://x.lnimg.com/photo/thumb_480/09ba5b97da4e47b1a97bac86e125001d.jpg 
2 http://x.lnimg.com/photo/thumb_480/580dcc66cd7f48d8aae8f583cd8e5e4b.jpg 
2 http://x.lnimg.com/photo/thumb_480/e62f6d11449b41ff93e191f6045cb304.jpg 
2 http://x.lnimg.com/photo/thumb_480/596230f07ebf471383991a99bd43420a.jpg 
2 http://x.lnimg.com/photo/thumb_480/da63be695fed4617b594d19e4aa0dc7a.jpg 
2 http://x.lnimg.com/photo/thumb_480/58f28244a2494c868006a97534e694e6.jpg 
2 http://x.lnimg.com/photo/thumb_480/1b0246dfe4314404b32147061198cf80.jpg 
2 http://x.lnimg.com/photo/thumb_480/b10a9bb8252f4d3d9638284f6f68fd6b.jpg 
2 http://x.lnimg.com/photo/thumb_480/48bf185da5f74a369dd629dd183bc8b3.jpg 
2 http://x.lnimg.com/photo/thumb_480/7008392330f847ecb3af7058ce0b2e3b.jpg 
2 http://x.lnimg.com/photo/thumb_480/fcf5618fc7d04265a912cce9f7dec344.jpg 
2 //x.lnimg.com/images/search/map/pinprofileclose2.gif 
2 
2 //x.lnimg.com/images/search/map/pinprofile-ViewDetails.gif 
2 http://ak.t0.tiles.virtualearth.net/tiles/r0?g=5289&mkt=en-us&lbl=l0&stl=h&shading=hill&n=z 
2 http://ak.dynamic.t1.tiles.virtualearth.net/comp/ch/0231?mkt=en-us&it=G,L&shading=hill&og=132&n=z&key=AhfWRPlwZlVGewL9th5vsIklmzvMkUMm8wx6pz5nXzgDlYXliZFSr6lBvgHYCZQj 

이 문서가 작품을 평가 말하는 방법입니다
casperjs --web-security=no --cookies-file=/tmp/mycookies.txt Script.js 
var casper = require('casper').create({ 
    verbose: true, 
}); 

//two different vars for two different pages of images 
var thumbNails, thumbNails2; 

function getThumbNails() { 
// Function to Scrape the links of thumbnails 
    var thumbNails = document.querySelectorAll('img'); 
    return Array.prototype.map.call(thumbNails, function (e) { 
     return e.getAttribute('src'); 
    }); 
}; 

// Scrubs target page below 
casper.start('http://looplink.ensemblere.com/SearchResults'); 

//Runs the function on page one, below 
casper.then(function() { 
    thumbNails = this.evaluate(getThumbNails); 
}); 

//Confirm that we are on page one of website, below 
casper.then(function(){ 
    if (this.exists('a.searchPagingButton.pagingPreviousButton')) { 
     this.echo('Second Page Is Loaded'); 
    } 
    else { 
     this.echo('First Page Is Loaded'); 
    } 
}); 

//Click on the next button to go to page two, below 
casper.thenClick('a.searchPagingButton.pagingNextButton'); 

//Confirm that we are on page two, below 
casper.then(function(){ 
    if (this.exists('a.searchPagingButton.pagingPreviousButton')) { 
     this.echo('Second Page Is Loaded') 
    } 
    else { 
     this.echo('First Page Is Loaded') 
    } 
}); 

//Runs the funciton for the second time, below; BUT HERE IS THE ISSUE ***** 
//idk why it pulls the same data twice, when the then statement above confirms we are on page two. 
casper.then(function() { 
    thumbNails2 = this.evaluate(getThumbNails); 
}); 

//Sort the data from the varaiables. 
casper.run(function() { 
    for(var i in thumbNails) { 
     console.log('1 ' + thumbNails[i]); 
    } 
    for(var i in thumbNails2) { 
     console.log('2 ' + thumbNails2[i]); 
    } 
    this.done(); 
}); 
+0

두 번째 페이지에 있는지 확인하기 위해 스크린 샷을 찍었습니까? –

+0

링크의 두 세트가 동일하지만 첫 페이지 또는 두 번째 링크의 링크 세트입니까? – deltab

+0

@ArtjomB. 나는 가지지 못했지만 좋은 시험이다. ".pagingPreviousButton"클래스는 두 번째 페이지에만 있기 때문에 그것에 대해 꽤 확신했지만 여전히 시도 할 것입니다. – Votlon

답변

0

오케이 소도 Artjom B.에서 화면 캡쳐가 끝난 것을 확인하기위한 의견이 나와 있습니다!

자원은 단순히 즉,로드되었다 : still loading picture

this.wait(40000, function() { 
    this.echo('Waited for 40 seconds'); 
}); 

캐스퍼을 추가하여 디버깅 스크린 샷 들어 40초

을 기다립니다 this.capture(/home/SuperDankDude/yourfilename.png)

나는 또한 모바일 것으로 나타났습니다 시도 간단한 해당 사이트의 버전은 전체 화면 버전과 다르기 때문에도 사용해야했습니다.

var casper = require('casper').create({ 
    verbose: true, 
}); 

//two different vars for two different pages of images 
var thumbNails, thumbNails2; 

casper.options.viewportSize = {width: 1920, height: 1080}; 

function getThumbNails() { 
// Function to Scrape the links of thumbnails 
    var thumbNails = document.querySelectorAll('img'); 
    return Array.prototype.map.call(thumbNails, function (e) { 
     return e.getAttribute('src'); 
    }); 
}; 

// Scrubs target page below 
casper.start('http://looplink.ensemblere.com/SearchResults'); 

//Runs the function on page one, below 
casper.then(function() { 
    thumbNails = this.evaluate(getThumbNails); 
}); 

//Confirm that we are on page one of website, below 
casper.then(function(){ 
    if (this.exists('a.searchPagingButton.pagingPreviousButton')) { 
     this.echo('Second Page Is Loaded'); 
    } 
    else { 
     this.echo('First Page Is Loaded') 
     this.capture("/home/votlon/WeB/firstpage.png"); 
    } 
}); 

//Click on the next button to go to page two, below 
casper.thenClick('a.searchPagingButton.pagingNextButton'); 

//Confirm that we are on page two, below 
casper.then(function(){ 
    if (this.exists('a.searchPagingButton.pagingPreviousButton')) { 
     this.echo('Second Page Is Loading') 
     this.wait(40000, function() { 
     this.echo('Waited for 40 seconds'); 
    }); 
     this.capture("/home/votlon/WeB/secondpage.png"); 
    } 
    else { 
     this.echo('First Page Is Loaded') 
    } 
}); 

//Runs the funciton for the second time, below; BUT HERE IS THE ISSUE ***** 
//idk why it pulls the same data twice, when the then statement above confirms we are on page two. 
casper.then(function() { 
    thumbNails2 = this.evaluate(getThumbNails); 
}); 

//Sort the data from the varaiables. 
casper.run(function() { 
    for(var i in thumbNails) { 
     console.log('1 ' + thumbNails[i]); 
    } 
    for(var i in thumbNails2) { 
     console.log('2 ' + thumbNails2[i]); 
    } 
    this.done(); 
}); 
+0

40 초를 기다릴 필요가 없습니다. 너무 길어요. 비동기 페이지로드 사이의 짧은 시간 동안 모달 대화 상자가 표시됩니다. 이 traversal과 일치시키기 위해 첫 번째'casper.waitUntilVisible (theUpdateModal)'과'casper.waitWhileVisible (theUpdateModal)'을 사용하라. –