2014-12-17 5 views
0

전체 페이지의 loc 태그 텍스트를 추출하고 추출 된 모든 텍스트의 수를 가져와야합니다. 다음 명령에 대한 루프를 반복하십시오. casper.open ('http://www.raybiztech.com/ ..... ') 다른 반복을 위해. below.I는 ("http://raybiztech.com/blog을") 특히 "LOC"에서 텍스트를 추출하고 casper.thenopen에 반복 원하는대로 위의 시나리오에 대한 하나의 도움casperjs를 사용하여 모든 loc 태그의 텍스트를 인쇄하는 방법

<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> 
     <url> 
      <loc>http://raybiztech.com/blog</loc> 
      <lastmod>2014-02-24</lastmod> 
     </url><url> 
      <loc>http://raybiztech.com/blog/application-development-maintenance</loc> 
      <lastmod>2014-02-14</lastmod> 
     </url><url> 
      <loc>http://raybiztech.com/blog/application-development-maintenance/analysis-services-testing-with-nick</loc> 
      <lastmod>2014-02-14</lastmod> 
     </url><url> 
      <loc>http://raybiztech.com/blog/application-development-maintenance/bi-solution-join-on-premises-to-windows-azure</loc> 
      <lastmod>2014-02-14</lastmod> 
     </url><url> 
      <loc>http://raybiztech.com/blog/application-development-maintenance/data-profiling-im-data-source-view</loc> 
      <lastmod>2014-02-14</lastmod> 
     </url><url> 
      <loc>http://raybiztech.com/blog/application-development-maintenance/data-programmability-tools-with-craig-lee</loc> 
      <lastmod>2014-02-14</lastmod> 
..... 

나는 코드를 업데이트 할 수;

var casper = new require('casper').Casper({ 
    verbose: true,   // log messages will be printed out to the console 
    logLevel: "debug",    // "Debug" level messages will be logged   
    safeLogs: false, 


}); 
    var fs = require('fs'); 
     var fname = new Date().getTime() + '.xml'; 
    var save = fs.pathJoin(fs.workingDirectory, 'raybiztech', fname); 

casper.test.begin('Payment Gateway',function(test) { 

/* 
* Start the browser with url http://lcdev.bluemodus.com/ 
*/ 
casper.start('http://www.raybiztech.com/sitemap.xml',function(){ 
    this.capture('/home/gopi/output/learningcounts/cmsHome.jpg'); 
    this.echo(this.getCurrentUrl()); 
    fs.write(save, this.getPageContent() + '\n', 'w'); 
    require('utils').dump(this.getElementsInfo('loc')); 


}); 
casper.viewport(1366,768); 
casper.run(function() { 
    test.done(); 
    casper.test.renderResults(true, 0, '/home/gopi/workspace/learningcounts/raybiztech.xml'); 
}); 
}); 

답변

0

text 속성을 포함하는 모든 항목 배열을 반환 casper.getElementsInfo 기능. 그런 다음 배열을 map으로 반복하여 객체를 text 속성 문자열로 변형 할 수 있습니다.

+0

코드를 제공하지 않았습니다. 주어진 포인터로 이것을하기가 정말 쉽기 때문입니다. –

+0

위의 코드 – gopi

+0

에 대한 업데이트를 제공합니다. 위의 코드에 어떤 문제가 있습니까? 답변을 얻은 후에는 질문을 수정하지 마십시오. –