Commit d71f794d by 马玮

login but no cookies

parent f13acd3d
......@@ -2,6 +2,7 @@
User: MaWei
Date: 2017.7.31
*/
'use strict';
const path = require('path');
const program = require('commander');
const config = require('config');
......@@ -10,17 +11,15 @@ const dealerSpider = require('./lib/dealerspider/index');
program
.version('0.1.0')
.option('-w, --website <website name>', 'Add website we want fetch')
.option('-a, --action <task action>', 'Add task we want to execute')
.option('-w, --webname <website name>', 'Add website we want fetch')
.option('-t, --task <task name>', 'Add task we want to execute')
.parse(process.argv);
(function() {
// console.log(process.pid);
// captcha.decode();
let spider = dealerSpider.getSpider({
'website': program.website
});
captcha_type = config.get('dealer_account')[program.website]['captcha_type'];
captcha.decode(captcha_type, program.website + '.png');
// spider.do(program.action);
}());
\ No newline at end of file
// console.log(process.pid);
let dealerWebInfo = config.get('Dealer')[program.webname];
let spider = new dealerSpider({
username : dealerWebInfo.username,
password : dealerWebInfo.password,
webname : program.webname,
task : program.task
}).execute();
\ No newline at end of file
......@@ -5,19 +5,19 @@ host = "http://api.dama2.com:7766/app/"
user = "test"
pwd = "test"
[Dealer.ifeng]
[Dealer.autoifeng]
username = "上海车城汽车"
password = "Checheng235#"
captchaType = "FOUR_CHARACTERS"
[Dealer.easypass]
username = "100074110"
password = "hnmz147852"
password = "hnmz147852."
captchaType = "ARITHMETIC"
[Dealer.autohome]
username = "河南明志汽车大迈8054"
password = "hnmz147852"
password = "hnmz147852."
captchaType = "FOUR_LETTERS"
[Captcha.ruokuai]
......
......@@ -3,10 +3,15 @@ const ruokuai = require('./ruokuai');
const captcha = exports;
captcha.decode = function (captchaType, imageFile, callback) {
console.log(captchaType);
console.log(imageFile);
console.info('captchaType:', captchaType);
console.info('imageFile:', imageFile);
const typeids = config.get('Captcha.ruokuai.typeids');
typeid = typeids[captchaType];
ruokuai.decode(typeid, imageFile, function (captcha) {
return new Promise(function (resolve, reject) {
ruokuai.decode(typeid, imageFile).then(function (captchaTxt) {
resolve(captchaTxt);
}).catch(function (error) {
console.error(error);
});
});
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ const request = require('request');
const filename = '2.png';
let ruokuai = exports;
ruokuai.decode = function (typeid, imageFile, callback) {
ruokuai.decode = function (typeid, imageFile) {
let ruokuaiInfo = config.get('Captcha.ruokuai');
const image = fs.createReadStream(imageFile);
formData = {
......@@ -18,12 +18,20 @@ ruokuai.decode = function (typeid, imageFile, callback) {
typeid: typeid,
image: fs.createReadStream(imageFile)
}
return new Promise(function (resolve, reject) {
request.post({url:'http://api.ruokuai.com/create.json', formData: formData}, function optionalCallback(err, httpResponse, body) {
if (err) {
return console.error('captcha decode failed:', err);
reject(new Error(err));
}
var captcha = JSON.parse(body);
console.log(captcha);
if (callback) callback(captcha);
try {
let captchaData = JSON.parse(body);
captchaTxt = captchaData.Result;
if (captchaTxt) {
resolve(captchaTxt);
}
} catch (e) {
reject(new Error(body));
}
});
});
}
'use strict';
process.env.NODE_CONFIG_DIR = '../config';
const fs = require('fs');
const phantom = require('phantom');
const cheerio = require('cheerio');
const config = require('config');
const captcha = require('../captcha');
class AutoHome {
constructor(params) {
this.name = 'autohome';
this.params = params;
console.log(params);
}
execute() {
return new Promise((resolve, reject) => {
switch (this.params.task) {
case 'login': {
console.log('do login');
this.login();
break;
}
case 'tryLogin': {
console.log('do login');
this.tryLogin();
break;
}
}
});
}
async tryLogin() {
const instance = await phantom.create(['--ignore-ssl-errors=yes']);
const page = await instance.createPage();
page.property('viewportSize', {width: 1920, height: 1080});
await page.on("onResourceRequested", function(requestData) {
console.info('Requesting', requestData.url);
});
const status = await page.open('http://ics.autohome.com.cn/passport/Home/Index');
console.log(status);
// data:image/png;base64, + baseTxt
await page.render('m5.png');
await instance.exit();
}
async login() {
const username = this.params.username;
const password = this.params.password;
const instance = await phantom.create(['--ignore-ssl-errors=yes']);
const page = await instance.createPage();
page.property('viewportSize', {width: 1920, height: 1080});
await page.on("onResourceRequested", function(requestData) {
console.info('Requesting', requestData.url);
});
const status = await page.open('http://ics.autohome.com.cn/passport/Home/Index');
await console.log(JSON.stringify(page.cookies()));
console.log(status);
console.log(username);
console.log(password);
page.render('m5.png');
const content = await page.property('content');
const $ = cheerio.load(content);
console.log('倒霉');
// data:image/png;base64, + baseTxt
page.property('clipRect', { top: 313, left: 1430, width: 64, height: 27 });
await page.renderBase64('PNG').then(base64text => {
const imageFile = 'tmp/' + (new Date) . getTime() + '.gif';
fs.writeFileSync(imageFile, base64text, 'base64');
const captchaType = config.get('Dealer')[this.name]['captchaType'];
captcha.decode(captchaType, imageFile).then((captchaTxt) => {
console.info('imageFile:', imageFile);
console.info('captchaTxt:', captchaTxt);
page.evaluate(function(username, password, captchaTxt) {
$('#UserNameDealer').val(username);
$('#PasswordDealer').val(password);
$('#checkCodeDealer').val(captchaTxt);
$('#btnDealer').trigger('click');
}, username, password, captchaTxt);
page.property('clipRect', { top: 0, left: 0, width: 1920, height: 1080 });
(async function() {
console.log('kkkkkkkkkk');
setTimeout(function(){
page.render('m7.png');
console.log(JSON.stringify(page.cookies()));
}, 5000);
})();
// await console.log(JSON.stringify(page.cookies()));
// await instance.exit();
}).catch((error) => {
console.error(error);
});
});
}
}
module.exports = AutoHome;
\ No newline at end of file
'use strict';
const phantom = require('phantom');
const cheerio = require('cheerio');
class AutoIfeng {
constructor(params) {
this.params = params;
console.log(params);
}
execute() {
return new Promise((resolve, reject) => {
switch (this.params.task) {
case 'login': {
console.log('do login');
this.login();
break;
}
case 'tryLogin': {
break;
}
}
});
}
async login() {
const passport = this.params.username;
const password = this.params.password;
const instance = await phantom.create(['--ignore-ssl-errors=yes']);
const page = await instance.createPage();
page.property('viewportSize', {width: 1920, height: 1080});
await page.on("onResourceRequested", function(requestData) {
console.info('Requesting', requestData.url)
});
const status = await page.open('http://dealer.auto.ifeng.com/dealerback/dealerIndexPage');
console.log(status);
console.log(passport);
page.evaluate(function(passport, password) {
document.querySelector('input[id=passport]').value = passport;
document.querySelector('input[id=password]').value = password;
}).then(function(html) {
console.log(html);
});
const content = await page.property('content');
const $ = cheerio.load(content)
console.log('倒霉');
await page.render('m2.png');
await instance.exit();
}
}
module.exports = AutoIfeng;
\ No newline at end of file
'use strict';
const phantom = require('phantom');
const cheerio = require('cheerio');
class EasyPass {
constructor() {
}
}
module.exports = EasyPass;
\ No newline at end of file
let dealerspider = exports;
'use strict';
const AutoIfeng = require('./autoifeng');
const AutoHome = require('./autohome');
const EasyPass = require('./easypass');
dealerspider.getSpider = function (data) {
console.log(data.website);
return this;
}
class DealerSpider {
constructor(params) {
let self = this;
let _params = {};
this.params = Object.assign(_params, params);
this.spider = this.getSpider();
}
dealerspider.do = function (action) {
console.log('I want ' + action);
}
getSpider() {
let spider;
switch (this.params.webname) {
case 'autoifeng': {
spider = new AutoIfeng(this.params);
break;
}
case 'autohome': {
spider = new AutoHome(this.params);
break;
}
case 'easypass': {
spider = new EasyPass(this.params);
break;
}
}
if (spider) {
return spider;
} else {
throw new Error('Spider not found');
}
}
dealerspider.login = function() {
console.log('login');
execute() {
this.spider.execute();
}
}
dealerspider.trylogin = function() {
console.log('trylogin');
}
module.exports = DealerSpider;
......@@ -13,8 +13,10 @@ program
.option('-w, --website <website name>', 'Add website we want fetch')
.parse(process.argv);
(function() {
captcha_type = config.get('Dealer')[program.website]['captchaType'];
const imagefile = 'images/' + program.website + '.png';
captcha.decode(captcha_type, imagefile);
}());
\ No newline at end of file
const captchaType = config.get('Dealer')[program.website]['captchaType'];
const imageFile = 'images/' + program.website + '.png';
captcha.decode(captchaType, imageFile).then((captchaTxt) => {
console.info('captchaTxt:', captchaTxt);
}).catch((error) => {
console.error(error);
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment