简体   繁体   English

CasperJS,页面停留在加载屏幕上

[英]CasperJS, Page Stuck on Loading Screen

I'm trying to use casperjs to grab a comment off of this page: 我正在尝试使用casperjs从此页面获取评论:

http://www.regulations.gov/#!documentDetail;D=APHIS-2013-0013-0083 http://www.regulations.gov/#!documentDetail;D=APHIS-2013-0013-0083

but when I navigate casper to it, it gets stuck on the 'loading' page. 但是当我导航到casper时,它卡在了“加载”页面上。 This is the image that I took using casper.capture(); 这是我使用casper.capture()拍摄的图像;

在此处输入图片说明

My full code: 我的完整代码:

var x = require('casper').selectXPath;

casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

casper.start('http://www.regulations.gov/#!documentDetail;D=APHIS-2013-0013-0083');

casper.then(function () {
casper.capture('ourImage1.png');
console.log('Copying comment from Regulations...');
casper.wait(3000, function() {
    var text = casper.fetchText(x('/html/body/div[3]/div[2]/div[2]/div[3]/div/table/tbody/tr/td[1]/div/div[3]/div[1]/div/div[2]'));
    console.log(text);
    casper.wait(3000, function() {
        casper.capture('ourImage2.png');
    });
});
});

casper.run();

I even gave it up to 30 seconds to load with casper.wait(), but nothing seems to work. 我什至花了30秒的时间来加载casper.wait(),但似乎没有任何效果。 It just gets stuck with the loading page. 它只是停留在加载页面上。

This works perfectly fine if you change this (horrible) userAgent or remove the line altogether: 如果您更改了此(可怕的) userAgent或完全删除了该行,则可以很好地工作:

casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');

It may be possible that the site provides special IE 6 optimized version that breaks phantomjs parsing. 该站点可能会提供特殊的IE 6优化版本,该版本会破坏phantomjs解析。 When I added the following code in front of the test, it displayed multiple errors that went away without the userAgent . 当我在测试之前添加以下代码时,它显示出多个错误,这些错误在没有userAgent情况下消失了。

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

casper.on("resource.error", function(resourceError){
    this.echo("res.err: " + JSON.stringify(resourceError));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM