CasperJS,页面卡在加载屏幕上 [英] CasperJS, Page Stuck on Loading Screen
问题描述
我正在尝试使用casperjs来获取此页面的评论:
I'm trying to use casperjs to grab a comment off of this page:
http://www.regulations.gov/#!documentDetail;D=APHIS-2013-0013-0083
但是当我将casper导航到它时,它会卡在加载页面上。这是我使用casper.capture()拍摄的图像;
but when I navigate casper to it, it gets stuck on the 'loading' page. This is the image that I took using casper.capture();
我的完整代码:
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();
我甚至用casper.wait()加载了30秒,但似乎没有工作。它只是卡在加载页面上。
I even gave it up to 30 seconds to load with casper.wait(), but nothing seems to work. It just gets stuck with the loading page.
推荐答案
如果你改变这个(可怕的)这很好用 userAgent
或完全删除该行:
This works perfectly fine if you change this (horrible) userAgent
or remove the line altogether:
casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
该网站可能提供特殊的IE 6优化版本,可以打破phantomjs解析。当我在测试前添加以下代码时,它显示多个错误,这些错误在没有 userAgent
的情况下消失。
It may be possible that the site provides special IE 6 optimized version that breaks phantomjs parsing. When I added the following code in front of the test, it displayed multiple errors that went away without the 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));
});
这篇关于CasperJS,页面卡在加载屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!