Commit ee696005 by 马玮

Fetch clues into testing database

parent 19e1740d
...@@ -25,7 +25,16 @@ sudo yum install redis ...@@ -25,7 +25,16 @@ sudo yum install redis
- [x] 功能:捕获程序错误及异常 - [x] 功能:捕获程序错误及异常
- [x] 功能:线索入库 - [x] 功能:线索入库
- [x] 功能:验证码解析完毕删除 - [x] 功能:验证码解析完毕删除
- [ ] 功能:线索入库前对数据进行基础校验,所有字段入库前检查去空格(50%) - [x] 功能:打码工具余额不足邮件报警
- [x] 功能:登录增加每天尝试登录限制,超过10次不再登录,防止第三方改版导致验证码浪费
- [x] 功能:代理随机切换
- [ ] 功能:登录错误细分(密码错误、验证码错误等区分处理入库)
- [x] 功能:线索车型映射
- [ ] 功能:线索顾客映射
- [ ] 功能:线索销售映射(不一定做)
- [ ] 功能:生成账号记录命令行工具
- [ ] 功能:发现第三方车型和本地不匹配将未知车型入库方便开发爬取同步车型
- [ ] 功能:线索入库前对数据进行基础校验(如车型不匹配等如何处理)
- [ ] 功能:Cluster分布式进程调度 - [ ] 功能:Cluster分布式进程调度
- [ ] 功能:增加日志系统 - [ ] 功能:增加日志系统
- [ ] 功能:增加随机userAgent - [ ] 功能:增加随机userAgent
......
...@@ -8,24 +8,40 @@ const program = require('commander'); ...@@ -8,24 +8,40 @@ const program = require('commander');
const config = require('config'); const config = require('config');
const captcha = require('./lib/captcha'); const captcha = require('./lib/captcha');
const Spider = require('./lib/spider'); const Spider = require('./lib/spider');
const poolCluster = require('./lib/database/poolCluster'); const DealerHelper = require('./lib/helpers/Dealer');
program program
.version('0.1.0') .version('0.1.0')
.option('-u, --userid <user id>', 'Assign our user id')
.option('-t, --task <task name>', 'Add task we want to execute') .option('-t, --task <task name>', 'Add task we want to execute')
.option('-w, --webname <website name>', 'Add website we want fetch') .option('-T, --thirdpartyAccountID <thirdparty account ID>', 'Assign thirdparty account ID')
.parse(process.argv); .parse(process.argv);
const commandError = [];
if (!program.thirdpartyAccountID) {
commandError.push('缺少thirdpartyAccountID!');
}
if (!program.task) {
commandError.push('缺少task!');
}
if (commandError.length > 0) {
console.log(commandError.join(': '));
program.outputHelp();
process.exit(1);
}
// console.log(process.pid); // console.log(process.pid);
poolCluster.getConnection('master', (err, connection) => { (async () => {
const dealerWebInfo = config.get(program.webname); const account = await DealerHelper.getAccount({
const spider = new Spider({ thirdpartyAccountID: program.thirdpartyAccountID
userid : program.userid,
task : program.task,
webname : program.webname,
username : dealerWebInfo.username,
password : dealerWebInfo.password
}); });
// new Buffer('hnmz147852.').toString('base64')
// new Buffer('Q2hlY2hlbmcyMzUj', 'base64').toString();
const params = Object.assign({
task: program.task,
thirdpartyAccountID: program.thirdpartyAccountID,
}, account);
const spider = new Spider(params);
spider.execute(); spider.execute();
}); })();
\ No newline at end of file \ No newline at end of file
...@@ -5,20 +5,20 @@ host = 'http://api.dama2.com:7766/app/' ...@@ -5,20 +5,20 @@ host = 'http://api.dama2.com:7766/app/'
user = 'test' user = 'test'
pwd = 'test' pwd = 'test'
[dealer.autoifeng] [autoifeng]
username = '上海车城汽车' username = '上海车城汽车'
password = 'Checheng235#' password = 'Checheng235#'
captcha_type = 'four_characters' captchaType = 'FOUR_CHARACTERS'
[dealer.easypass] [easypass]
username = '100074110' username = '100074110'
password = 'hnmz147852.' password = 'hnmz147852.'
captcha_type = 'arithmetic' captchaType = 'ARITHMETIC'
[dealer.autohome] [autohome]
username = '河南明志汽车大迈8054' username = '河南明志汽车大迈8054'
password = 'hnmz147852.' password = 'hnmz147852.'
captcha_type = 'four_letters' captchaType = 'FOUR_LETTERS'
[captcha.ruokuai] [captcha.ruokuai]
username = 'chedev' username = 'chedev'
...@@ -27,13 +27,26 @@ softid = 86134 ...@@ -27,13 +27,26 @@ softid = 86134
softkey = 'b167ed636a224990a2f04ae2d28d1542' softkey = 'b167ed636a224990a2f04ae2d28d1542'
[captcha.ruokuai.typeids] [captcha.ruokuai.typeids]
four_letters = 2040 # 四个英文字母 FOUR_LETTERS = 2040 # 四个英文字母
four_characters = 3040 # 四个字母数字混合 FOUR_CHARACTERS = 3040 # 四个字母数字混合
arithmetic = 7100 # 算术题 ARITHMETIC = 7100 # 算术题
[db.master] [DB.NODES.MASTER_CRM]
host = 'localhost' host = 'rm-bp10h7b832629p429o.mysql.rds.aliyuncs.com'
port = 3306 port = 3306
user = 'root' user = 'car_base'
password = 'root' password = 'car_base2046'
database = 'test' database = 'car_crm'
connectionLimit = 500
[DB.NODES.MASTER_CAR]
host = 'rm-bp10h7b832629p429o.mysql.rds.aliyuncs.com'
port = 3306
user = 'car_base'
password = 'car_base2046'
database = 'car_new_test'
connectionLimit = 500
[CLUE_INPUT_TYPE]
autohome = 18
easypass = 21
[DB.NODES.MASTER_CRM]
host = 'rm-bp10h7b832629p429o.mysql.rds.aliyuncs.com'
port = 3306
user = 'car_base'
password = 'car_base2046'
database = 'car_crm'
connectionLimit = 500
[DB.NODES.MASTER_CAR]
host = 'rm-bp10h7b832629p429o.mysql.rds.aliyuncs.com'
port = 3306
user = 'car_base'
password = 'car_base2046'
database = 'car_new_test'
connectionLimit = 500
\ No newline at end of file
const config = require('config');
const poolCluster = require('./database/poolCluster');
// 自定义模块
class DI {
constructor(params) {
this.params = params;
}
static async getConnection(nodeID) {
return new Promise(function(resolve, reject) {
poolCluster.getConnection(nodeID, function (err, connection) {
if (err) {
reject(err);
} else {
resolve(connection);
}
});
});
}
}
module.exports = DI;
\ No newline at end of file
// process.env.NODE_CONFIG_DIR = '../../config'; // process.env.NODE_CONFIG_DIR = '../../config';
const config = require('config'); const config = require('config');
const mysql = require('mysql2'); const mysql = require('mysql');
const clusterConfig = { const clusterConfig = {
removeNodeErrorCount: 5, removeNodeErrorCount: 5,
defaultSelector: 'RR' defaultSelector: 'RR'
}; };
const poolCluster = mysql.createPoolCluster(clusterConfig); const poolCluster = mysql.createPoolCluster(clusterConfig);
const db = config.get('db'); const nodes = config.get('DB.NODES');
for (let [nodeId, nodeConfig] of Object.entries(db)) { for (let [nodeID, nodeConfig] of Object.entries(nodes)) {
console.log(nodeConfig); console.log(nodeConfig);
poolCluster.add(nodeId, nodeConfig); poolCluster.add(nodeID, nodeConfig);
} }
module.exports = poolCluster; module.exports = poolCluster;
const redis = require('redis'); const redis = require('redis');
const config = require('config');
const moment = require('moment'); const moment = require('moment');
const errors = require('../errors'); const errors = require('../errors');
const Promise = require('bluebird'); const Promise = require('bluebird');
const poolCluster = require('../database/poolCluster'); const poolCluster = require('../database/poolCluster');
const DI = require('../DI');
Promise.promisifyAll(redis); Promise.promisifyAll(redis);
class DealerHelper { class DealerHelper {
static async getCookies(params) { static async getCookies(params) {
return new Promise(async (resolve, reject) => {
try { try {
const client = await redis.createClient(); const account = await this.getAccount({
const cookies_key = params.webname + '_cookies'; thirdpartyAccountID: params.thirdpartyAccountID
let cookies = JSON.parse(await client.getAsync(cookies_key)); });
await client.quit(); try {
return cookies; let cookies = JSON.parse(account['cookies']);
resolve(cookies);
} catch (e) { } catch (e) {
return null; reject(e);
} }
} catch (e) {
reject(e);
}
});
} }
static async getHeaderCookie(params) { static async getHeaderCookie(params) {
...@@ -35,6 +43,7 @@ class DealerHelper { ...@@ -35,6 +43,7 @@ class DealerHelper {
} }
static async saveCookies(params) { static async saveCookies(params) {
return new Promise(async (resolve, reject) => {
try { try {
// 延长过期时间为一个月后 // 延长过期时间为一个月后
await params.cookies.forEach((cookie) => { await params.cookies.forEach((cookie) => {
...@@ -42,55 +51,162 @@ class DealerHelper { ...@@ -42,55 +51,162 @@ class DealerHelper {
cookie.expires = moment().add(30, 'days').toString(); cookie.expires = moment().add(30, 'days').toString();
}); });
const cookie_key = params.webname + '_cookies'; const sql = `UPDATE crm_dealer_thirdparty_account SET cookies = ? WHERE id = ?`;
const client = await redis.createClient(); const replacements = [JSON.stringify(params.cookies), params.thirdpartyAccountID];
await client.set(cookie_key, JSON.stringify(params.cookies)); console.log(replacements);
await client.quit(); const connection = await DI.getConnection('MASTER_CRM');
connection.query(
sql,
replacements,
function(err, results, fields) {
connection.release();
if (err) {
reject(err);
} else {
console.info('cookie保存成功'); console.info('cookie保存成功');
resolve(true);
}
}
);
} catch (e) { } catch (e) {
return e; reject(e);
} }
});
}
// 获取账号信息
static async getAccount(params) {
return new Promise(async (resolve, reject) => {
let whereStr;
let replacements;
if (params.thirdpartyAccountID) {
replacements = [params.thirdpartyAccountID];
whereStr = 'id = ?';
} else if (params.dealerId && params.webname) {
replacements = [params.dealerId, params.webname];
whereStr = 'dealerID = ? AND webname = ?';
}
const connection = await DI.getConnection('MASTER_CRM');
const sql = `SELECT * FROM crm_dealer_thirdparty_account WHERE ${whereStr}`;
connection.query(
sql,
replacements,
function(err, results, fields) {
connection.release();
if (err) {
reject(err);
} else {
const account = results[0];
if (account.password) {
account.password = new Buffer(account.password, 'base64').toString();
}
resolve(account);
}
}
);
});
}
// 线索车系映射
static async mapClues(params) {
return new Promise(async (resolve, reject) => {
const webname = params.webname || '';
let clues = params.clues || [];
const connection = await DI.getConnection('MASTER_CAR');
// 获取车型车系文本
let intentionStrs = clues.map(clue => clue.intentionDes);
// 车系车系文本去重
intentionStrs = Array.from(new Set(intentionStrs));
let sql;
if (webname === 'autohome') {
sql = `SELECT CAR_BRAND_TYPE_ID AS id, CAR_BRAND_TYPE_NAME AS name FROM car_brand_type_info
WHERE ${connection.escape(intentionStrs.join())} LIKE CONCAT('%', CAR_BRAND_TYPE_NAME, '%')`;
} else if (webname === 'easypass') {
sql = `SELECT car_brand_type_id AS id, yc_series_name AS name FROM relation_series_yiche
WHERE car_brand_type_id > 0
AND ${connection.escape(intentionStrs.join())} LIKE CONCAT('%', yc_series_name, '%')`;
} else {
console.log('未知类型');
}
connection.query(sql, function(err, intentions, fields) {
connection.release();
if (err) {
reject(err);
} else {
clues.forEach((clue) => {
clue.createdAt = moment(clue.createdAt).format('X');
intentions.forEach((intention) => {
if (clue.intentionDes.includes(intention.name)) {
clue.intentionID = intention.id;
}
});
});
// console.log(JSON.stringify(intentions));
// console.log(JSON.stringify(clues));
// reject(err);
resolve(clues);
}
});
});
} }
// 保存线索 // 保存线索
static async saveClues(params) { static async saveClues(params) {
const userid = params.userid || 0; const dealerID = params.dealerID || 0;
const clues = params.clues || [];
const webname = params.webname || ''; const webname = params.webname || '';
if (!userid || !clues.length || !webname) { let clues = params.clues || [];
if (!dealerID || !clues.length || !webname) {
throw errors.AppError('Params missing'); throw errors.AppError('Params missing');
} }
poolCluster.getConnection('master', function (err, connection) { clues = await this.mapClues(params).catch((e) => {
const updated_at = moment().format('YYYY-MM-DD HH:mm:ss'); console.log(e);
});
const connection = await DI.getConnection('MASTER_CRM');
const updatedAt = moment().format('YYYY-MM-DD HH:mm:ss');
const valuesSql = []; const valuesSql = [];
const _clue = { const _clue = {
customerid: 0,
customerName: '', customerName: '',
customerPhone: '', customerPhone: '',
customerArea: '', customerArea: '',
licenseArea: '', licenseArea: '',
expectCar: '', intentionDes: '',
intentionID: 0,
salesName: '', salesName: '',
salesPhone: '', salesPhone: '',
createdAt: '0000-00-00 00:00:00', createdAt: 0,
}; };
for (let clue of clues) { for (let clue of clues) {
clue = Object.assign(_clue, clue); clue = Object.assign(_clue, clue);
let valueSql = '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; let valueSql = '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
let inserts = [userid, params.webname, // customer_id, shop_name, salesman_id需要映射
clue.customerName, clue.customerPhone, clue.licenseArea, clue.expectCar, let replacements = [
clue.salesName, clue.salesPhone, clue.createdAt, updated_at]; 0, clue.customerName, clue.customerPhone, clue.intentionDes, clue.intentionID, '', dealerID, clue.salesName, 0,
config.get('CLUE_INPUT_TYPE')[params.webname], clue.createdAt
];
valueSql = connection.format(valueSql, inserts); valueSql = connection.format(valueSql, replacements);
valuesSql.push(valueSql); valuesSql.push(valueSql);
} }
const sql = `INSERT INTO clue ( const sql = `INSERT INTO crm_clue2 (
userid, webname, customer_name, customer_phone, license_area, expect_car, customer_id, customer_name, customer_phone, intention_des, intention_id, shop_name, shop_id,
sales_name, sales_phone, created_at, updated_at salesman_name, salesman_id, clue_input_type, create_time
) VALUES ${valuesSql.join(',')} ON DUPLICATE KEY UPDATE updated_at = VALUES(updated_at)`; ) VALUES ${valuesSql.join(',')} ON DUPLICATE KEY UPDATE
customer_name = VALUES(customer_name),
intention_des = VALUES(intention_des),
shop_name = VALUES(shop_name)`;
console.log(sql); console.log(sql);
connection.query( connection.query(
...@@ -111,7 +227,6 @@ class DealerHelper { ...@@ -111,7 +227,6 @@ class DealerHelper {
} }
} }
); );
});
} }
} }
......
...@@ -42,6 +42,7 @@ class Autohome { ...@@ -42,6 +42,7 @@ class Autohome {
} }
async tryLogin() { async tryLogin() {
return new Promise(async (resolve, reject) => {
try { try {
let newCookies; let newCookies;
let oldCookies = await DealerHelper.getCookies(this.params); let oldCookies = await DealerHelper.getCookies(this.params);
...@@ -72,16 +73,20 @@ class Autohome { ...@@ -72,16 +73,20 @@ class Autohome {
console.log('newCookies:', JSON.stringify(newCookies)); console.log('newCookies:', JSON.stringify(newCookies));
await DealerHelper.saveCookies(params); await DealerHelper.saveCookies(params);
if (this.params.task === 'tryLogin') {
console.log('尝试登陆成功'); console.log('尝试登陆成功');
} resolve(true);
return true;
} else { } else {
throw new errors.TryLoginError('尝试登录失败'); if (this.params.task === 'tryLogin') {
console.log('尝试登录失败');
return;
} else {
reject(new errors.TryLoginError('尝试登录失败'));
}
} }
} catch (e) { } catch (e) {
throw new errors.TryLoginError(`尝试登录异常: ${e}`); reject(new errors.TryLoginError(`尝试登录异常: ${e}`));
} }
});
} }
async login() { async login() {
...@@ -103,6 +108,8 @@ class Autohome { ...@@ -103,6 +108,8 @@ class Autohome {
const username = this.params.username; const username = this.params.username;
const password = this.params.password; const password = this.params.password;
console.log('用户名:', username);
console.log('密码:', password);
const horseman = new Horseman({ const horseman = new Horseman({
ignoreSSLErrors: true ignoreSSLErrors: true
...@@ -130,7 +137,7 @@ class Autohome { ...@@ -130,7 +137,7 @@ class Autohome {
// 验证码解码 // 验证码解码
let captchaText; let captchaText;
try { try {
const captchaType = config.get(this.params.webname)['captcha_type']; const captchaType = config.get(this.params.webname)['captchaType'];
captchaText = await captcha.decodeBase64(captchaType, base64Text); captchaText = await captcha.decodeBase64(captchaType, base64Text);
console.info('captchaText:', captchaText); console.info('captchaText:', captchaText);
} catch (e) { } catch (e) {
...@@ -151,13 +158,14 @@ class Autohome { ...@@ -151,13 +158,14 @@ class Autohome {
await await
horseman horseman
.click('[id="btnDealer"]') .click('[id="btnDealer"]')
.waitForNextPage({ timeout: 5000 }) .wait(2000)
.waitForNextPage({ timeout: 10000 })
.screenshot('m3.png') .screenshot('m3.png')
.exists('#loginout'); .exists('#loginout');
if (loginSuccess) { if (loginSuccess) {
console.log('登录成功!'); console.log('登录成功!');
const cookies = await horseman .cookies(); const cookies = await horseman.cookies();
const params = this.params; const params = this.params;
params.cookies = cookies; params.cookies = cookies;
console.log(JSON.stringify(cookies)); console.log(JSON.stringify(cookies));
...@@ -203,7 +211,7 @@ class Autohome { ...@@ -203,7 +211,7 @@ class Autohome {
params.provinceId = -2; params.provinceId = -2;
params.cityId = -2; params.cityId = -2;
params.status = -1; params.status = -1;
params.startTime = moment().subtract(3, 'days').format('YYYY.MM.DD'); params.startTime = moment().subtract(90, 'days').format('YYYY.MM.DD');
params.endtime = moment().format('YYYY.MM.DD'); params.endtime = moment().format('YYYY.MM.DD');
params.pageIndex = 1 params.pageIndex = 1
params.pageSize = 20; params.pageSize = 20;
...@@ -235,7 +243,7 @@ class Autohome { ...@@ -235,7 +243,7 @@ class Autohome {
const clues = []; const clues = [];
for (let l of clueData.result.list) { for (let l of clueData.result.list) {
const clue = {}; const clue = {};
customerIndex++; customerIndex += 1;
// 名字字符串样本:<a href='#' onclick='showCusDetailWithId("303590")'>田华</a><br/><span></span> // 名字字符串样本:<a href='#' onclick='showCusDetailWithId("303590")'>田华</a><br/><span></span>
const idMatch = l.CustomerNameStr.match(/showCusDetailWithId\("(\d+)"\)/) || []; const idMatch = l.CustomerNameStr.match(/showCusDetailWithId\("(\d+)"\)/) || [];
// 手机地区字符串样本:13253979998<br/>河南 三门峡 // 手机地区字符串样本:13253979998<br/>河南 三门峡
...@@ -253,7 +261,7 @@ class Autohome { ...@@ -253,7 +261,7 @@ class Autohome {
clue.orderType = l.OrderTypeStr.trim(); clue.orderType = l.OrderTypeStr.trim();
clue.orderState = l.OrderStateStr.trim(); clue.orderState = l.OrderStateStr.trim();
clue.licenseArea = l.LicenseCityStr.trim(); clue.licenseArea = l.LicenseCityStr.trim();
clue.expectCar = l.SpecNameStr.trim(); clue.intentionDes = l.SpecNameStr.trim();
clue.createdAt = l.LeadTimeStr.trim(); clue.createdAt = l.LeadTimeStr.trim();
clues.push(clue); clues.push(clue);
...@@ -266,7 +274,7 @@ class Autohome { ...@@ -266,7 +274,7 @@ class Autohome {
console.log('销售号码:', clue.salesPhone); console.log('销售号码:', clue.salesPhone);
console.log('线索获得时间:', clue.createdAt); console.log('线索获得时间:', clue.createdAt);
console.log('上牌地区:', clue.licenseArea); console.log('上牌地区:', clue.licenseArea);
console.log('线索意向车型:', clue.expectCar); console.log('线索意向车型:', clue.intentionDes);
// TODO: just for debug, remove them later // TODO: just for debug, remove them later
console.log('线索类型:', clue.orderType); console.log('线索类型:', clue.orderType);
...@@ -274,20 +282,20 @@ class Autohome { ...@@ -274,20 +282,20 @@ class Autohome {
console.log('==========================================================================='); console.log('===========================================================================');
} }
if (this.params.userid) { if (this.params.dealerID) {
await DealerHelper.saveClues({ await DealerHelper.saveClues({
clues: clues, clues: clues,
userid: this.params.userid, dealerID: this.params.dealerID,
webname: this.params.webname webname: this.params.webname
}); });
} }
// 判断是否抓取完全 // 判断是否抓取完全
if (customerIndex < rowcount) { if (customerIndex < rowcount) {
let randomSecs = randomInt(1, 8); let randomSecs = randomInt(1, 2);
console.log(`随机等待${randomSecs}秒`); console.log(`随机等待${randomSecs}秒`);
await Promise.delay(randomSecs*1000).then(async function() { await Promise.delay(randomSecs*1000).then(async function() {
params.pageIndex++; params.pageIndex += 1;
await fetchByPage(); await fetchByPage();
}); });
} }
......
...@@ -127,7 +127,7 @@ class Easypass { ...@@ -127,7 +127,7 @@ class Easypass {
// 验证码解码 // 验证码解码
let captchaText; let captchaText;
try { try {
const captchaType = config.get(this.params.webname)['captcha_type']; const captchaType = config.get(this.params.webname)['captchaType'];
captchaText = await captcha.decodeBase64(captchaType, base64Text); captchaText = await captcha.decodeBase64(captchaType, base64Text);
console.info('captchaText:', captchaText); console.info('captchaText:', captchaText);
} catch (e) { } catch (e) {
...@@ -196,7 +196,7 @@ class Easypass { ...@@ -196,7 +196,7 @@ class Easypass {
console.log('networkRequest', networkRequest); console.log('networkRequest', networkRequest);
}); });
const txtBeginTime = moment().subtract(9, 'days').format('YYYY-MM-DD'); const txtBeginTime = moment().subtract(90, 'days').format('YYYY-MM-DD');
await await
horseman horseman
...@@ -227,9 +227,10 @@ class Easypass { ...@@ -227,9 +227,10 @@ class Easypass {
const nameAreaMatch = customerNameAreaStr.match(/(.*?)\[(.*?)\]/); const nameAreaMatch = customerNameAreaStr.match(/(.*?)\[(.*?)\]/);
clue.customerName = (nameAreaMatch[1] || '').trim(); clue.customerName = (nameAreaMatch[1] || '').trim();
clue.customerArea = clue.licenseArea = (nameAreaMatch[2] || '').trim(); clue.licenseArea = (nameAreaMatch[2] || '').trim();
clue.customerArea = clue.licenseArea;
clue.customerPhone = (ptitlePieces[1] || '').replace('电话', '').trim(); clue.customerPhone = (ptitlePieces[1] || '').replace('电话', '').trim();
clue.expectCar = (ptitlePieces[2] || '').replace('订购', '').trim(); clue.intentionDes = (ptitlePieces[2] || '').replace('订购', '').trim();
// 提交时间样本:提交时间:2017-08-10 08:31 // 提交时间样本:提交时间:2017-08-10 08:31
const customerCreatedAtStr = $(this).find('.msg p a span:contains(提交时间)').text() || ''; const customerCreatedAtStr = $(this).find('.msg p a span:contains(提交时间)').text() || '';
...@@ -242,15 +243,15 @@ class Easypass { ...@@ -242,15 +243,15 @@ class Easypass {
console.log('客户号码:', clue.customerPhone); console.log('客户号码:', clue.customerPhone);
console.log('上牌地区:', clue.customerArea); console.log('上牌地区:', clue.customerArea);
console.log('负责销售:', clue.salesName); console.log('负责销售:', clue.salesName);
console.log('线索意向车型:', clue.expectCar); console.log('线索意向车型:', clue.intentionDes);
console.log('线索获得时间:', clue.createdAt); console.log('线索获得时间:', clue.createdAt);
console.log('==========================================================================='); console.log('===========================================================================');
}); });
if (this.params.userid) { if (this.params.dealerID) {
await DealerHelper.saveClues({ await DealerHelper.saveClues({
clues: clues, clues: clues,
userid: this.params.userid, dealerID: this.params.dealerID,
webname: this.params.webname webname: this.params.webname
}); });
} }
...@@ -266,7 +267,7 @@ class Easypass { ...@@ -266,7 +267,7 @@ class Easypass {
.waitForSelector('#UpdatePanel1') .waitForSelector('#UpdatePanel1')
.screenshot('list3.png'); .screenshot('list3.png');
let randomSecs = randomInt(1, 5); let randomSecs = randomInt(1, 2);
console.log(`随机等待${randomSecs}秒`); console.log(`随机等待${randomSecs}秒`);
await Promise.delay(randomSecs*1000).then(async function() { await Promise.delay(randomSecs*1000).then(async function() {
await fetchByPage(); await fetchByPage();
......
...@@ -4,23 +4,22 @@ const dealer = require('./dealer'); ...@@ -4,23 +4,22 @@ const dealer = require('./dealer');
class Spider { class Spider {
constructor(params) { constructor(params) {
let self = this; let self = this;
let _params = {}; this.params = Object.assign({}, params);
this.params = Object.assign(_params, params);
this.spider = this.getSpider(); this.spider = this.getSpider();
} }
getSpider() { getSpider() {
let spider; let spider;
switch (this.params.webname) { switch (this.params.webname) {
case 'dealer.autoifeng': { case 'autoifeng': {
spider = new dealer.AutoIfeng(this.params); spider = new dealer.Autoifeng(this.params);
break; break;
} }
case 'dealer.autohome': { case 'autohome': {
spider = new dealer.Autohome(this.params); spider = new dealer.Autohome(this.params);
break; break;
} }
case 'dealer.easypass': { case 'easypass': {
spider = new dealer.Easypass(this.params); spider = new dealer.Easypass(this.params);
break; break;
} }
......
UPDATE `crm_dd_input_type` SET `name`='易车' WHERE (`id`='21')
ALTER TABLE `crm_clue`
ADD INDEX `customer_car` (`shop_id`, `clue_input_type`, `customer_phone`, `intention_des`, `create_time`) ;
\ No newline at end of file
...@@ -7,9 +7,41 @@ const fs = require('fs'); ...@@ -7,9 +7,41 @@ const fs = require('fs');
const moment = require('moment'); const moment = require('moment');
const day = moment().subtract(3, 'days').format('YYYY.MM.DD'); const day = moment().subtract(3, 'days').format('YYYY.MM.DD');
const axios = require('axios'); const axios = require('axios');
const config = require('config');
console.log(moment('2017-08-09 09:56').format('X'));
return;
console.log(config.get('clueInputType')['dealer.autohome']);
return;
// best
// import { es6 } from './AirbnbStyleGuide';
// export default es6;
// // good
// // filename es6.js
// import { es6 } from './AirbnbStyleGuide';
// export default es6;
// // good
// import foo, { named1, named2 } from 'foo';
//
// // good
// import foo, {
// named1,
// named2,
// } from 'foo';
//
// // good
// export default function foo() {}
// use args, use toString in class
(function () {
console.log('Welcome to the Internet. Please follow me.');
}());
console.log(moment().add(1, 'days').toString()); console.log(moment().add(1, 'days').toString());
console.log(moment().toString()); console.log(moment().toString());
throw '1';
return; return;
console.log(fs.existsSync('/tmp/a') && fs.statSync('/tmp/a').isFile()); console.log(fs.existsSync('/tmp/a') && fs.statSync('/tmp/a').isFile());
......
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