【问题标题】:Phantomjs/Casperjs is not evaluating the JS/Ajax on the German amazon site properlyPhantomjs/Casperjs 没有正确评估德国亚马逊网站上的 JS/Ajax
【发布时间】:2013-08-12 11:44:45
【问题描述】:

我遇到了德国亚马逊网站的问题。

此 URL http://www.amazon.de/Angebote/b/ref=cs_top_nav_gb27?ie=UTF8&node=872398 链接到德国 Amazon-Deal 网站。

网站上有一个名为“Aktuelle Blitzangebote”的部分,它在一天中的特定时间提供多种交易。

如果我尝试通过 phantomjs 访问“ul.ulResized”中的交易(“Aktuelle Blitzangebote 框中的交易”),不知何故不会加载它们。

我使用以下脚本从站点中获取 HTML-src:

var casper = require("casper").create({
    pageSettings: {
                 userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
                  viewportSize: {width: 1600, height: 900}
     }

});
var fs = require('fs');

 var address = casper.cli.args[0].replace(/\^/g,"");

 console.log("Address == " + address);

casper.on('remote.message', function (msg) {
      this.echo('remote message caught: ' + msg);
});

casper.start(address);

casper.wait(5000);
casper.then(function()
       {
           console.log("writing");
           fs.write("blitz.html", this.getHTML(), "w");
           console.log("done");
       });

casper.run();

有人可以帮我解决这个问题吗?

最好的问候, 奥戈夫

【问题讨论】:

    标签: javascript ajax amazon phantomjs casperjs


    【解决方案1】:

    你可以这样做:

    var url = 'http://www.amazon.de/Angebote/b/ref=cs_top_nav_gb27?ie=UTF8&node=872398';
    
        var casper = require('casper').create({
            verbose: false,
            logLevel: 'debug'
        });
    
        casper.test.comment('Starting Testing');
        casper.start(url, function() {
            console.log(this.getCurrentUrl());
    
            this.test.assertHttpStatus(200, siteName + ' is up');
    
            this.wait(5000, function(){
                console.log(this.getHTML(".ulResized "));
            });
    
        });
    
        casper.run(function() {
            this.echo('So the whole suite ended.');
            this.exit();
        });
    

    您还应该能够使用以下命令选择特定的<li>:

    console.log(this.getHTML(".ulResized li:nth-child(1)")); //replace 1 with list order number
    

    【讨论】:

      猜你喜欢
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多