CasperJS,试图刮一张桌子

时间:2017-07-06 11:28:30

标签: javascript phantomjs casperjs

此函数应提取所有表行,但不起作用。它没有输出。

var casper = require("casper").create({
pageSettings: {
    userAgent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36"
},
verbose: true,
logLevel: 'debug'
});


var url = 'http://cnt.rm.ingv.it/';
casper.start(url);//
casper.waitForSelector('#dataTablesEvents', processPage, stopScript);
casper.run();


var stopScript = function() {
     casper.echo("STOPPING SCRIPT").exit();
};

var processPage = function() {

    pageData = this.evaluate(getPageData);

    if (this.exists('a[rel="next"]') == false) {
        stopScript();
    }

    this.thenClick('a[rel="next"]').then(function() {
        this.waitForSelector("#dataTablesEvents", processPage, stopScript);
    });
 };

function getPageData(){

   var rows = casper.evaluate(function(){
       return document.querySelectorAll("table tbody tr");
   });

   return rows;
}

我尝试调试,这就是结果:

[debug] [phantom] opening url: http://cnt.rm.ingv.it/, HTTP GET
[debug] [phantom] Navigation requested: url=http://cnt.rm.ingv.it/, 
type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://cnt.rm.ingv.it/"
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] start page is loaded
[info] [phantom] Step _step 3/3 http://cnt.rm.ingv.it/ (HTTP 200)
[info] [phantom] Step _step 3/3: done in 945ms.
[info] [phantom] waitFor() finished in 40ms.
[info] [phantom] Done 3 steps in 1003ms
[debug] [phantom] Navigation requested: url=about:blank, type=Other, 
willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"

我无法理解这一点..就像WaitForSelector无法启动..任何帮助?

1 个答案:

答案 0 :(得分:0)

这是一种适合你的方式:

$('.show12 li').show();
$('.show12 li').not(':eq('+random1+'), :eq('+random2+')').hide();