autologin.js
var request = require("request");
var cheerio = require('cheerio');
var $;
var post = function(form) {
request.post({
followAllRedirects: true,
url: 'http://202.162.79.194/login/sz/hotspotlogin.php',
form: form
}, function(error, response, body) {
console.log(body);
});
}
var req2 = function(url) {
var form = {};
request({
followAllRedirects: true,
url: url
}, function(error, response, body) {
$ = cheerio.load(response.body);
$('INPUT').each(function(i, elem) {
console.log(elem.attribs);
form[elem.attribs.name] = elem.attribs.value;
if (elem.attribs.type == "checkbox") {
elem.checked = true;
}
});
post(form);
});
}
request({
followAllRedirects: true,
url: "http://192.168.182.1:3990/prelogin"
}, function(error, response, body) {
if (!error) {
$ = cheerio.load(response.body);
$('a').each(function(i, elem) {
var url = "http://202.162.79.194/login/sz/" + elem.attribs.href;
req2(url);
});
}
});