关于如何调用loginToNetflix方法,我有哪些选项?有没有一种更干净和优雅的方法来完成这个任务?
loginToNetflix(credentials.username, credentials.password);
function loginToNetflix (username, password) {
casper.start('https://www.netflix.com/Login?locale=en-US', function() {
this.echo('Attempting login to Netflix - filling and submitting login form');
this.fill('form#login-form', {
'email': username,
'password': password,
'RememberMe': true
}, true);
});
casper.then(function() {
this.echo('Login Complete - Please check the cookie as defined in command line');
//save the cookie for use by netflix scraper api
var cookies = JSON.stringify(phantom.cookies);
fs.write("netflix-cookies.txt", cookies, 644);
});
casper.run(function () {
this.echo('Done - Exiting!');
casper.exit();
});
}发布于 2015-03-19 08:28:01
在我看来没问题。这对我个人来说是个小麻烦,但一个可能的改进是在一个对象中传递凭据。
var credentials = {
username: "xxx",
password: "yyy"
};这将使函数的签名更小,毕竟,从语义上讲,这两个变量是紧密耦合的。
但就像我说的,[医]小果胶。在我看来不错。
https://codereview.stackexchange.com/questions/84360
复制相似问题