Skip to content

Instantly share code, notes, and snippets.

@ppeeou
Created November 14, 2017 17:32
Show Gist options
  • Select an option

  • Save ppeeou/82c616e7ee1b607f37d8f0ec9992a465 to your computer and use it in GitHub Desktop.

Select an option

Save ppeeou/82c616e7ee1b607f37d8f0ec9992a465 to your computer and use it in GitHub Desktop.
//CasperJS 객체 생성
var express = require('express');
var app = express();
var casper_nodejs = require('casper-nodejs');
app.get('/auth/github/callback', (req, res, next) => {
console.log('server callback ok')
res.json('callback')
})
app.get('/', (req, res, next) => {
var url = "github url";
var casper = casper_nodejs.create(url);
// once the page is loaded, execute that in our current nodejs context
casper.then(function executed_in_this_context() {
console.log("page loaded");
});
casper.then(function executed_in_casperjs_context() {
this.evaluate(function executed_in_this_context() {
document.getElementById("login_field").value = "githubid";
document.getElementById("password").value = "githubpassword";
document.querySelector('.btn-primary').click();
});
}, function (ret) {
console.log('first form filled');
});
casper.then(function executed_in_casperjs_context() {
return 42;
}, function executed_in_this_context(ret) {
console.log("it works: " + ret);
// echo results in some pretty fashion
res.json('ok')
casper.exit();
});
casper.run();
})
app.listen(3000, function () {
console.log('server start');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment