CasperJS 登录 Ghost CMS 并截图
CasperJS Login into Ghost CMS and take screenshot
到目前为止,这是我的脚本。
我还在代码下方为你们发布了输出。
它运行时不会停止,也不会 returns 屏幕截图会挂起,没有任何错误。
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
}
});
casper.start('https://dilionsmith.me/ghost/#/signin', function() {
this.waitForSelector('form[method="post"]');
});
casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
identification: 'email',
password: 'pass'
}, true);
});
casper.then(function() {
casper.capture('after.png');
});
casper.run();
输出:
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: https://dilionsmith.me/ghost/#/signin, HTTP GET
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/signin, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/signin"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 578ms.
[info] [phantom] Step _step 3/5 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step _step 3/5: done in 598ms.
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"
问题是您没有在 '':
上包含输入名称
casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
identification: 'email',
password: 'pass'
}, true);
});
应该是:
casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
'identification': 'email',
'password': 'pass'
}, true);
});
希望对您有所帮助。
到目前为止,这是我的脚本。
我还在代码下方为你们发布了输出。
它运行时不会停止,也不会 returns 屏幕截图会挂起,没有任何错误。
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: true,
loadPlugins: true,
userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0'
}
});
casper.start('https://dilionsmith.me/ghost/#/signin', function() {
this.waitForSelector('form[method="post"]');
});
casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
identification: 'email',
password: 'pass'
}, true);
});
casper.then(function() {
casper.capture('after.png');
});
casper.run();
输出:
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: https://dilionsmith.me/ghost/#/signin, HTTP GET
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/signin, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/signin"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 578ms.
[info] [phantom] Step _step 3/5 https://dilionsmith.me/ghost/#/signin (HTTP 200)
[info] [phantom] Step _step 3/5: done in 598ms.
[debug] [phantom] Navigation requested: url=https://dilionsmith.me/ghost/#/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"
[debug] [phantom] url changed to "https://dilionsmith.me/ghost/#/"
问题是您没有在 '':
上包含输入名称casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
identification: 'email',
password: 'pass'
}, true);
});
应该是:
casper.then(function() {
console.log("page loaded");
this.fill('form[method="post"]', {
'identification': 'email',
'password': 'pass'
}, true);
});
希望对您有所帮助。