Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Casper.js获取网页并显示_Javascript_Html_Casperjs - Fatal编程技术网

Javascript Casper.js获取网页并显示

Javascript Casper.js获取网页并显示,javascript,html,casperjs,Javascript,Html,Casperjs,有没有办法使用casper.js登录页面,然后显示页面? 我可以拍摄屏幕截图,我希望它是真实的页面 这是我到目前为止所知道的,尽管我确信这是非常错误的: var casper = require('casper').create({ viewportSize: { width: 1365, height: 768 }, // engine: 'slimmerjs', verbose: true, logLevel: "debug", pageSettings: { loadIm

有没有办法使用casper.js登录页面,然后显示页面? 我可以拍摄屏幕截图,我希望它是真实的页面

这是我到目前为止所知道的,尽管我确信这是非常错误的:

var casper = require('casper').create({
 viewportSize: {
    width: 1365,
    height: 768
},
// engine: 'slimmerjs',
verbose: true,
logLevel: "debug",
pageSettings: {
loadImages: false,//The script is much faster when this field is set to false
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36  (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'
}
});

//First step is to open
casper.start().thenOpen("http://mysite/login", function() {
console.log("mysite website opened");
});

//Now we have to populate username and password, and submit the form
casper.then(function(){
console.log("Login using username and password");
this.evaluate(function(){
document.getElementById("user_email").value="me";
document.getElementById("user_password").value="password";
document.getElementById('new_user').submit();
});
});
casper.thenOpen('http://mysite/report/70?dashboard_id=2', function(){
console.log("Make a screenshot of morning info and save it as  pic.png"); 
this.wait(10000, function(){
this.captureSelector('pic.png','.highcharts- container');
});
});

casper.start("http://mysite/report/70?dashboard_id=2", function() {
this.page.switchToChildFrame(0);
this.page.switchToParentFrame();
});

casper.run(function() {
  this.exit();
});


casper.run();

如果您想捕获HTML,这是在Casper中实现的方法

在需要此捕获时(登录后…),在等待快照的相同时间内。。试试这个:

this.wait(10000, function(){
    this.captureSelector('pic.png','.highcharts- container');

    var HTML = document.createElement('textarea);
    HTML.innerHTML = this.getHTML();
    console.log(HTML.value);  // or use the variable for something else
});

使用CasperJS执行web抓取已经4年了,这是我能设计出的唯一有效的方法,并为我提供了良好的可解析HTML

你能定义一下你所说的
是什么意思吗?我希望它是实际的页面?你想下载源代码吗?还是别的?@user2720970等待
submit()
完成,然后再打开下一个URL。您在等待
http://mysite/report/70?dashboard_id=2
,但不是为了完成提交