[英]node.js authenticate login form
我正在使用一個login.aspx頁面,其中有一個登錄表單(用戶名/密碼)。
有沒有辦法通過代碼設置用戶名和密碼,以便我可以從網站上獲取其他頁面?
您將要使用PhantomJS或CasperJS(包裝器)之類的東西。
看看這個答案 ,例如:
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
loadImages: false, // The WebPage instance used by Casper will
loadPlugins: false, // use these settings
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
}
});
// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
this.echo("Page Error: " + msg, "ERROR");
});
var url = 'http://www.facebook.com/';
casper.start(url, function() {
// search for 'casperjs' from google form
console.log("page loaded");
this.test.assertExists('form#login_form', 'form is found');
this.fill('form#login_form', {
email: '**<put your email here>**',
pass: '**<put your password here>**'
}, true);
});
casper.thenEvaluate(function(){
console.log("Page Title " + document.title);
console.log("Your name is " + document.querySelector('.headerTinymanName').textContent );
});
casper.run();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.