【问题标题】:CasperJS not loading javascripts?CasperJS不加载javascripts?
【发布时间】:2016-08-11 21:23:00
【问题描述】:
var casper = require('casper').create({
viewportSize: {
    width: 1920,
    height: 1080
},
verbose: true,
logLevel: 'debug'
});

var utils = require('utils');
casper.options.onResourceRequested = function(C, requestData, request) {
    utils.dump(requestData.headers);
};
var url = casper.cli.get('url');
var filename = casper.cli.get('filename');
var headers = casper.cli.get('storefront');

if (headers != null) {
    casper.userAgent('iTunes/12.4.3 (Windows; Microsoft Windows 10.0 x64 Business Edition (Build 9200); x64) AppleWebKit/7601.6016.1000.7');
}

casper.start().then(function() {
    casper.page.customHeaders = {
        'X-Apple-Store-Front': headers,
        'X-Apple-Tz': '3600'
    };
    casper.thenOpen(url, function() {
       this.wait(2000, function() {
        var fs = require('fs');
        fs.write('asd.html', this.getHTML(), 'wb');
        this.capture(filename);
    });
});
});
casper.run();

casperjs screenshot.js --storefront="143441-1,12 ab:SwTTXLh0" --url="https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewGrouping?cc=us&id=37" --filename=tv.jpg

当试图转储这个页面时,它并没有给我完整的 javascript 轮播或任何东西。老实说,我不知道是什么导致加载失败,想知道是否有人对此有任何其他经验?

PhantonJS 版本是 2.1.1。 CasperJS 版本是 1.1.1。

【问题讨论】:

  • 您使用哪个 PhantomJS 版本?请注册resource.errorpage.errorremote.messagecasper.page.onResourceTimeout 活动 (Example)。可能有错误。
  • 更新了帖子。 Error: ITSExceptionHandler: ITSExceptionHandler:{message:"ReferenceError: Can't find variable: iTunes", url:"https://itunes.apple.com/htmlResources/CBCB/dt-storefront-base.js", lineNumber:"1023"}Error: ReferenceError: Can't find variable: iTunescasperjs 版本为 1.1.1
  • PhantomJS 也是 2.1.1。

标签: javascript web-scraping casperjs


【解决方案1】:

我也面临同样的问题。这个PhantomJS ticket有几件事要检查:

  • 尝试输出 Casper 使用 this.debugHTML() 解释的 html 以查看您要加载的脚本是否在实际 html 中(可能由于怪异/旧 userAgent 而被省略)
  • 您正在使用的 Webkit 版本
  • 尝试通过onResourceRequestedonResourceReceived 查看网络流量,看看是否确实请求和接收了脚本。

遗憾的是,在我的情况下,所有这些看起来都不错,但页面仍然是空白的。希望它可以帮助别人。如果您对检查内容有其他提示,请告诉我。

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    相关资源
    最近更新 更多