使用CasperJS加载基于ajax的动态内容

时间:2015-11-11 20:23:30

标签: javascript web-scraping phantomjs casperjs

我正在尝试使用casperjs从PlayStation商店加载数据。每当我尝试访问该页面时,我都会获得标准的非加载html。由于页面构建自己的javascript我不知道从这里去哪里。如果我试着打电话给我,我就得到一个黑色的方块。

var links = [];
var casper = require('casper').create({verbose: true,
    logLevel: "debug"});
var username = casper.cli.get('username');
var password = casper.cli.get('password');


casper.start('https://auth.api.sonyentertainmentnetwork.com/login.jsp?request_locale=en_US', function() {
    casper.echo(casper.getPageContent());
    this.fill('form[id="signInForm"]', {'j_username': username, 'j_password': password}, true);
});

casper.thenOpen('https://store.playstation.com/#!/en-us/library/main', function() {
    links = document.querySelectorAll('li.firstCell.lastCell.cellGridVideoLibraryMain');    
    this.echo(this.getHTML());
});


casper.run(function() { 
    this.echo(links.length + ' links found:');
    this.echo(' - ' + links.join('\n - ')).exit();
});

0 个答案:

没有答案