Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
马玮
/
carspider
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0f13c593
authored
Aug 25, 2017
by
马玮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix await
parent
3a7fcc58
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
313 additions
and
275 deletions
+313
-275
boot.js
+21
-15
lib/DI.js
+2
-2
lib/spider/dealer/Autohome.js
+3
-4
lib/spider/dealer/Easypass.js
+1
-1
lib/spider/index.js
+1
-1
test.js
+285
-252
No files found.
boot.js
View file @
0f13c593
...
...
@@ -49,24 +49,29 @@ if (commandError.length > 0) {
const
spider
=
new
Spider
(
params
);
await
spider
.
execute
();
// console.timeEnd('程序耗时');
console
.
timeEnd
(
'程序耗时'
);
// process.exit(0);
return
;
const
rl
=
readline
.
createInterface
({
input
:
process
.
stdin
,
output
:
process
.
stdout
});
// rl.write('正在释放资源...\n预计3秒后退出: ');
// DI.shutdownLogger(async () => {
// for (let i = 3; i > 0; i -= 1) {
// rl.write(String(i));
// await Promise.delay(1000);
// readline.moveCursor(process.stdout,-1);
// }
// readline.clearLine(process.stdout, 0);
// readline.moveCursor(process.stdout, -1, -1);
// rl.write('\n');
// rl.close();
// console.log('程序结束');
// process.exit(0);
// });
DI
.
shutdownLogger
(()
=>
{
// do nothing
});
rl
.
write
(
'正在释放资源...\n预计3秒后退出: '
);
for
(
let
i
=
3
;
i
>
0
;
i
-=
1
)
{
rl
.
write
(
String
(
i
));
await
Promise
.
delay
(
1000
);
readline
.
moveCursor
(
process
.
stdout
,
-
1
);
}
readline
.
clearLine
(
process
.
stdout
,
0
);
readline
.
moveCursor
(
process
.
stdout
,
-
1
,
-
1
);
rl
.
write
(
'\n'
);
rl
.
close
();
console
.
log
(
'程序结束'
);
process
.
exit
(
0
);
})();
\ No newline at end of file
lib/DI.js
View file @
0f13c593
...
...
@@ -9,7 +9,7 @@ class DI {
}
static
getLogger
()
{
const
level
=
process
.
env
.
LOG_LEVEL
||
'
info
'
;
const
level
=
process
.
env
.
LOG_LEVEL
||
'
debug
'
;
log4js
.
configure
({
appenders
:
{
console
:
{
type
:
'console'
},
...
...
@@ -19,7 +19,7 @@ class DI {
default
:
{
appenders
:
[
'console'
,
'carspider'
],
level
:
level
}
}
});
return
log4js
.
getLogger
();
return
log4js
.
getLogger
(
'SPIDER'
);
}
static
shutdownLogger
(
cb
)
{
...
...
lib/spider/dealer/Autohome.js
View file @
0f13c593
...
...
@@ -39,8 +39,7 @@ class Autohome extends Base {
return
;
}
case
'fetchClues'
:
{
await
this
.
fetchClues
();
return
;
return
await
this
.
fetchClues
();
}
}
}
...
...
@@ -202,7 +201,7 @@ class Autohome extends Base {
params
.
provinceId
=
-
2
;
params
.
cityId
=
-
2
;
params
.
status
=
-
1
;
params
.
startTime
=
moment
().
subtract
(
90
,
'days'
).
format
(
'YYYY.MM.DD'
);
params
.
startTime
=
moment
().
subtract
(
3
,
'days'
).
format
(
'YYYY.MM.DD'
);
params
.
endtime
=
moment
().
format
(
'YYYY.MM.DD'
);
params
.
pageIndex
=
1
params
.
pageSize
=
20
;
...
...
@@ -215,7 +214,7 @@ class Autohome extends Base {
logger
.
info
(
`线索日期:
${
params
.
startTime
}
-
${
params
.
endtime
}
`
);
}
logger
.
info
(
`线索页面:
${
params
.
pageIndex
}
`
);
axios
.
get
(
'http://ics.Autohome.com.cn/Dms/Order/SearchOrderList'
,
{
a
wait
a
xios
.
get
(
'http://ics.Autohome.com.cn/Dms/Order/SearchOrderList'
,
{
params
:
params
,
headers
:{
Cookie
:
headerCookie
...
...
lib/spider/dealer/Easypass.js
View file @
0f13c593
...
...
@@ -195,7 +195,7 @@ class Easypass extends Base {
console
.
log
(
'networkRequest'
,
networkRequest
);
});
const
txtBeginTime
=
moment
().
subtract
(
90
,
'days'
).
format
(
'YYYY-MM-DD'
);
const
txtBeginTime
=
moment
().
subtract
(
15
,
'days'
).
format
(
'YYYY-MM-DD'
);
await
horseman
...
...
lib/spider/index.js
View file @
0f13c593
...
...
@@ -32,7 +32,7 @@ class Spider {
}
async
execute
()
{
this
.
spider
.
execute
();
await
this
.
spider
.
execute
();
}
}
...
...
test.js
View file @
0f13c593
const
Promise
=
require
(
'bluebird'
);
const
redis
=
require
(
"redis"
);
const
client
=
redis
.
createClient
();
const
Horseman
=
require
(
'node-horseman'
);
Promise
.
promisifyAll
(
require
(
"redis"
));
const
fs
=
require
(
'fs'
);
const
moment
=
require
(
'moment'
);
const
day
=
moment
().
subtract
(
3
,
'days'
).
format
(
'YYYY.MM.DD'
);
const
axios
=
require
(
'axios'
);
const
config
=
require
(
'config'
);
async
function
t
()
{
return
't'
;
}
const
DI
=
require
(
'./lib/DI'
);
const
logger
=
DI
.
getLogger
();
try
{
}
catch
(
e
)
{
}
return
// new Buffer('hnmz147852.').toString('base64')
// new Buffer('Q2hlY2hlbmcyMzUj', 'base64').toString();
let
i
=
0
;
async
function
test
(
l
)
{
i
+=
1
;
await
Promise
.
delay
(
l
*
1000
).
then
(
async
function
()
{
logger
.
info
(
'过了'
+
l
+
'秒'
);
logger
.
info
((
new
Date
()).
toLocaleString
());
logger
.
info
(
'======================================='
);
if
(
i
<
8
)
{
test
(
1
);
}
else
{
return
true
;
}
});
}
(
async
()
=>
{
await
test
(
1
).
then
(
async
()
=>
{
await
DI
.
shutdownLogger
(
async
()
=>
{
console
.
log
(
'牛逼啊'
);
});
});
return
;
const
mt
=
await
t
();
console
.
log
(
mt
);
return
;
console
.
log
((
new
Date
()).
toDateString
());
// const global_var = '全局变量';
// const test_fun = () => {
// console.log(global_var);
// }
// test_fun();
let
list
=
[
1
,
2
,
3
,
4
,
5
];
for
(
l
of
list
)
{
console
.
log
((
new
Date
()).
toLocaleString
());
await
test
(
l
);
}
})();
return
;
function
testCatch
()
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
try
{
throw
new
Error
(
'傻B'
);
}
catch
(
e
)
{
console
.
log
(
'拒绝'
,
e
);
reject
(
e
);
}
finally
{
console
.
log
(
'finally'
);
}
});
}
testCatch
().
catch
((
e
)
=>
{
console
.
log
(
'逮到你喽'
,
e
);
});
return
;
const
updatedAt
=
moment
().
format
(
'YYYY-MM-DD HH:mm:ss'
);
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
().
toString
());
throw
'1'
;
return
;
console
.
log
(
fs
.
existsSync
(
'/tmp/a'
)
&&
fs
.
statSync
(
'/tmp/a'
).
isFile
());
return
;
// console.log(moment().subtract(30, 'days').format('YYYY.MM.DD'));
// return;
// const cookie = require('cookie');
// console.log(cookie.serialize('foo', 'bar'));
// const redis = require("redis");
// const client = redis.createClient();
// const Horseman = require('node-horseman');
// Promise.promisifyAll(require("redis"));
// const fs = require('fs');
// const moment = require('moment');
// const day = moment().subtract(3, 'days').format('YYYY.MM.DD');
// const axios = require('axios');
// const config = require('config');
// async function t () {
// return 't';
// }
// const DI = require('./lib/DI');
// const logger = DI.getLogger();
//
//
// // new Buffer('hnmz147852.').toString('base64')
// // new Buffer('Q2hlY2hlbmcyMzUj', 'base64').toString();
//
// let i = 0;
// async function test (l) {
// i += 1;
// await Promise.delay(l*1000).then(async function() {
// logger.info('过了' + l + '秒');
// logger.info((new Date()).toLocaleString());
// logger.info('=======================================');
// if (i < 8) {
// await test(1);
// } else {
// return true;
// }
// });
// }
//
//
// (async () => {
//
//
//
//
//
//
// return;
// const getCookies = async () => {
// const client = await redis.createClient();
// const cookies_key = 'autohome_cookies';
// let cookies = JSON.parse(await client.getAsync(cookies_key));
// let a = [];
// await cookies.forEach((c) => {
// c.expires = (new Date()).getTime() + (1000 * 60 * 60);
// a.push(`${c.name}=${c.value}`);
// // for (let [k, v] of Object.entries(c)) {
// // a.push(`${k}=${v}`);
// // }
// const readline = require('readline');
// await test(1);
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
// a = a.join(';');
// // console.log(a);
// // return;
// await client.quit();
//
// let url = 'http://ics.autohome.com.cn/Dms/Order/SearchOrderList';
// url = 'http://ics.autohome.com.cn/passport/Home/Index';
// // url = 'https://www.zhihu.com/';
// for (let i = 3; i > 0; i -= 1) {
// rl.write(String(i));
// await Promise.delay(1000);
// readline.moveCursor(process.stdout,-1);
// }
// readline.clearLine(process.stdout, 0);
// readline.moveCursor(process.stdout, -1, -1);
// rl.write('\n');
// rl.close();
// console.log('程序结束');
// process.exit(0);
//
//
// return;
//
// axios.get(url, {
// withCredentials: true,
// headers:{
// Cookie: a
// const mt = await t();
// console.log(mt);
// return;
// console.log((new Date()).toDateString());
// // const global_var = '全局变量';
// // const test_fun = () => {
// // console.log(global_var);
// // }
// // test_fun();
// let list = [1, 2, 3, 4, 5];
// for (l of list) {
// console.log((new Date()).toLocaleString());
// await test(l);
// }
// }).then(res => {
// console.log(JSON.stringify(res.data));
// const writeStream = fs.createWriteStream('test2.html');
// writeStream.write(JSON.stringify(res.data));
// });
// })();
// return;
//
// got(url, {
// headers: {
// 'Cookie': a
// function testCatch() {
// return new Promise(async (resolve, reject) => {
// try {
// throw new Error('傻B');
// } catch (e) {
// console.log('拒绝', e);
// reject(e);
// } finally {
// console.log('finally');
// }
// }).then(response => {
// // response.body = '';
// // console.log(response);
// const writeStream = fs.createWriteStream('test2.html');
// writeStream.write(JSON.stringify(response.body));
// });
// }
// getCookies();
// testCatch().catch((e) => {
// console.log('逮到你喽', e);
// });
// return;
// let info = 'showCusDetailWithId("302761")';
// var m = info.match(/showCusDetailWithId\("(\d*)"\)/);
// console.log(m);
//
// const updatedAt = moment().format('YYYY-MM-DD HH:mm:ss');
// console.log(moment('2017-08-09 09:56').format('X'));
// return;
// class AppError extends Error {
// constructor (message, status) {
//
//
// Calling parent constructor of base Error class.
//
super(message)
;
//
console.log(config.get('clueInputType')['dealer.autohome']);
//
return
;
//
// // Capturing stack trace, excluding constructor call from it.
// Error.captureStackTrace(this, this.constructor);
// // 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() {}
//
// // Saving class name in the property of our custom error as a shortcut.
// this.name = this.constructor.name;
// // use args, use toString in class
// (function () {
// console.log('Welcome to the Internet. Please follow me.');
// }());
//
//
// You can use any additional properties you want.
//
// I'm going to use preferred HTTP status for this error types.
//
// `500` is the default value if not specified.
//
this.status = status || 500
;
//
console.log(moment().add(1, 'days').toString());
//
console.log(moment().toString());
//
throw '1';
//
return
;
//
// }
// };
// class AppError extends Error {
// constructor(message) {
// super(message);
// this.message = message;
// // this.name = 'MyError';
// this.name = this.constructor.name;
// }
// }
// console.log(fs.existsSync('/tmp/a') && fs.statSync('/tmp/a').isFile());
// return;
//
// class BError extends AppError {
// constructor (fields) {
// // Overriding both message and status code.
// super('Request validation failed', 400);
// // Saving custom property.
// this.fields = fields || {};
// }
// };
// function OperationalError(message) {
// if (!(this instanceof OperationalError))
// return new OperationalError(message);
// notEnumerableProp(this, "name", "OperationalError");
// notEnumerableProp(this, "message", message);
// this.cause = message;
// this["isOperational"] = true;
//
// if (message instanceof Error) {
// notEnumerableProp(this, "message", message.message);
// notEnumerableProp(this, "stack", message.stack);
// } else if (Error.captureStackTrace) {
// Error.captureStackTrace(this, this.constructor);
// }
// // console.log(moment().subtract(30, 'days').format('YYYY.MM.DD'));
// // return;
//
// }
// // const cookie = require('cookie');
// // console.log(cookie.serialize('foo', 'bar'));
// // return;
//
// response{status:success, message, name:}
// responseError
// function peg$computePosDetails() {
// throw new BError('语法错误', 'idsssss');
// }
// // const getCookies = async () => {
// // const client = await redis.createClient();
// // const cookies_key = 'autohome_cookies';
// // let cookies = JSON.parse(await client.getAsync(cookies_key));
// // let a = [];
// // await cookies.forEach((c) => {
// // c.expires = (new Date()).getTime() + (1000 * 60 * 60);
// // a.push(`${c.name}=${c.value}`);
// // // for (let [k, v] of Object.entries(c)) {
// // // a.push(`${k}=${v}`);
// // // }
// // });
// // a = a.join(';');
// // // console.log(a);
// // // return;
// // await client.quit();
// //
// // let url = 'http://ics.autohome.com.cn/Dms/Order/SearchOrderList';
// // url = 'http://ics.autohome.com.cn/passport/Home/Index';
// // // url = 'https://www.zhihu.com/';
// //
// // axios.get(url, {
// // withCredentials: true,
// // headers:{
// // Cookie: a
// // }
// // }).then(res => {
// // console.log(JSON.stringify(res.data));
// // const writeStream = fs.createWriteStream('test2.html');
// // writeStream.write(JSON.stringify(res.data));
// // });
// // return;
// //
// // got(url, {
// // headers: {
// // 'Cookie': a
// // }
// // }).then(response => {
// // // response.body = '';
// // // console.log(response);
// // const writeStream = fs.createWriteStream('test2.html');
// // writeStream.write(JSON.stringify(response.body));
// // });
// // }
// // getCookies();
// // return;
//
// try {
// peg$computePosDetails();
// } catch (e) {
// // let info = 'showCusDetailWithId("302761")';
// // var m = info.match(/showCusDetailWithId\("(\d*)"\)/);
// // console.log(m);
// // return;
//
//
// // class AppError extends Error {
// // constructor (message, status) {
// //
// // // Calling parent constructor of base Error class.
// // super(message);
// //
// // // Capturing stack trace, excluding constructor call from it.
// // Error.captureStackTrace(this, this.constructor);
// //
// // // Saving class name in the property of our custom error as a shortcut.
// // this.name = this.constructor.name;
// //
// // // You can use any additional properties you want.
// // // I'm going to use preferred HTTP status for this error types.
// // // `500` is the default value if not specified.
// // this.status = status || 500;
// //
// // }
// // };
//
// // class AppError extends Error {
// // constructor(message) {
// // super(message);
// // this.message = message;
// // // this.name = 'MyError';
// // this.name = this.constructor.name;
// // }
// // }
// //
// // class BError extends AppError {
// // constructor (fields) {
// // // Overriding both message and status code.
// // super('Request validation failed', 400);
// // // Saving custom property.
// // this.fields = fields || {};
// // }
// // };
//
// // function OperationalError(message) {
// // if (!(this instanceof OperationalError))
// // return new OperationalError(message);
// // notEnumerableProp(this, "name", "OperationalError");
// // notEnumerableProp(this, "message", message);
// // this.cause = message;
// // this["isOperational"] = true;
// //
// // if (message instanceof Error) {
// // notEnumerableProp(this, "message", message.message);
// // notEnumerableProp(this, "stack", message.stack);
// // } else if (Error.captureStackTrace) {
// // Error.captureStackTrace(this, this.constructor);
// // }
// //
// // }
// //
//
// // response{status:success, message, name:}
// // responseError
// // function peg$computePosDetails() {
// // throw new BError('语法错误', 'idsssss');
// // }
// //
// // try {
// // peg$computePosDetails();
// // } catch (e) {
// // console.log(e);
// // };
// // return;
//
// const testHorseman = async () => {
// const horseman = new Horseman();
// await
// horseman
// .userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
// .viewport(1920, 1080)
// .open('https://www.zhihu.com/')
// .then(() => {
// console.log((new Date()).toLocaleString());
// })
// .waitForSelector('.subtitle', { timeout: 2000 })
// .screenshot('zhihu.png')
// .error(function (e) {
// console.error("这是一个错误: ", e);
// })
// .catch(function(e) {
// console.log(e);
// };
// return;
// console.log('难道是这里?');
// })
// // .catch(Horseman.TimeoutError, function(e) {
// // console.log('等待超时');
// // console.log(e);
// // console.log((new Date()).toLocaleString());
// // })
// .close();
// }
const
testHorseman
=
async
()
=>
{
const
horseman
=
new
Horseman
();
await
horseman
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
.
viewport
(
1920
,
1080
)
.
open
(
'https://www.zhihu.com/'
)
.
then
(()
=>
{
console
.
log
((
new
Date
()).
toLocaleString
());
})
.
waitForSelector
(
'.subtitle'
,
{
timeout
:
2000
})
.
screenshot
(
'zhihu.png'
)
.
error
(
function
(
e
)
{
console
.
error
(
"这是一个错误: "
,
e
);
function
promise
(){
return
Promise
.
delay
(
1000
).
then
(
function
()
{
console
.
log
(
'111111'
,
new
Date
());
})
.
catch
(
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
'难道是这里?'
);
})
// .catch(Horseman.TimeoutError, function(e) {
// console.log('等待超时');
// console.log(e);
// console.log((new Date()).toLocaleString());
// })
.
close
();
}
async
function
test
()
{
await
promise
()
console
.
log
(
'222222'
,
new
Date
());
}
(
async
()
=>
{
await
test
().
then
(
async
()
=>
{
await
Promise
.
delay
(
1000
);
console
.
log
(
'3333333'
,
new
Date
());
});
})()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment