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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
319 additions
and
282 deletions
+319
-282
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
+291
-259
No files found.
boot.js
View file @
0f13c593
...
@@ -49,24 +49,29 @@ if (commandError.length > 0) {
...
@@ -49,24 +49,29 @@ if (commandError.length > 0) {
const
spider
=
new
Spider
(
params
);
const
spider
=
new
Spider
(
params
);
await
spider
.
execute
();
await
spider
.
execute
();
// console.timeEnd('程序耗时');
console
.
timeEnd
(
'程序耗时'
);
// process.exit(0);
return
;
const
rl
=
readline
.
createInterface
({
const
rl
=
readline
.
createInterface
({
input
:
process
.
stdin
,
input
:
process
.
stdin
,
output
:
process
.
stdout
output
:
process
.
stdout
});
});
// rl.write('正在释放资源...\n预计3秒后退出: ');
// DI.shutdownLogger(async () => {
DI
.
shutdownLogger
(()
=>
{
// for (let i = 3; i > 0; i -= 1) {
// do nothing
// rl.write(String(i));
});
// await Promise.delay(1000);
// readline.moveCursor(process.stdout,-1);
rl
.
write
(
'正在释放资源...\n预计3秒后退出: '
);
// }
for
(
let
i
=
3
;
i
>
0
;
i
-=
1
)
{
// readline.clearLine(process.stdout, 0);
rl
.
write
(
String
(
i
));
// readline.moveCursor(process.stdout, -1, -1);
await
Promise
.
delay
(
1000
);
// rl.write('\n');
readline
.
moveCursor
(
process
.
stdout
,
-
1
);
// rl.close();
}
// console.log('程序结束');
readline
.
clearLine
(
process
.
stdout
,
0
);
// process.exit(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 {
...
@@ -9,7 +9,7 @@ class DI {
}
}
static
getLogger
()
{
static
getLogger
()
{
const
level
=
process
.
env
.
LOG_LEVEL
||
'
info
'
;
const
level
=
process
.
env
.
LOG_LEVEL
||
'
debug
'
;
log4js
.
configure
({
log4js
.
configure
({
appenders
:
{
appenders
:
{
console
:
{
type
:
'console'
},
console
:
{
type
:
'console'
},
...
@@ -19,7 +19,7 @@ class DI {
...
@@ -19,7 +19,7 @@ class DI {
default
:
{
appenders
:
[
'console'
,
'carspider'
],
level
:
level
}
default
:
{
appenders
:
[
'console'
,
'carspider'
],
level
:
level
}
}
}
});
});
return
log4js
.
getLogger
();
return
log4js
.
getLogger
(
'SPIDER'
);
}
}
static
shutdownLogger
(
cb
)
{
static
shutdownLogger
(
cb
)
{
...
...
lib/spider/dealer/Autohome.js
View file @
0f13c593
...
@@ -39,8 +39,7 @@ class Autohome extends Base {
...
@@ -39,8 +39,7 @@ class Autohome extends Base {
return
;
return
;
}
}
case
'fetchClues'
:
{
case
'fetchClues'
:
{
await
this
.
fetchClues
();
return
await
this
.
fetchClues
();
return
;
}
}
}
}
}
}
...
@@ -202,7 +201,7 @@ class Autohome extends Base {
...
@@ -202,7 +201,7 @@ class Autohome extends Base {
params
.
provinceId
=
-
2
;
params
.
provinceId
=
-
2
;
params
.
cityId
=
-
2
;
params
.
cityId
=
-
2
;
params
.
status
=
-
1
;
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
.
endtime
=
moment
().
format
(
'YYYY.MM.DD'
);
params
.
pageIndex
=
1
params
.
pageIndex
=
1
params
.
pageSize
=
20
;
params
.
pageSize
=
20
;
...
@@ -215,7 +214,7 @@ class Autohome extends Base {
...
@@ -215,7 +214,7 @@ class Autohome extends Base {
logger
.
info
(
`线索日期:
${
params
.
startTime
}
-
${
params
.
endtime
}
`
);
logger
.
info
(
`线索日期:
${
params
.
startTime
}
-
${
params
.
endtime
}
`
);
}
}
logger
.
info
(
`线索页面:
${
params
.
pageIndex
}
`
);
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
,
params
:
params
,
headers
:{
headers
:{
Cookie
:
headerCookie
Cookie
:
headerCookie
...
...
lib/spider/dealer/Easypass.js
View file @
0f13c593
...
@@ -195,7 +195,7 @@ class Easypass extends Base {
...
@@ -195,7 +195,7 @@ class Easypass extends Base {
console
.
log
(
'networkRequest'
,
networkRequest
);
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
await
horseman
horseman
...
...
lib/spider/index.js
View file @
0f13c593
...
@@ -32,7 +32,7 @@ class Spider {
...
@@ -32,7 +32,7 @@ class Spider {
}
}
async
execute
()
{
async
execute
()
{
this
.
spider
.
execute
();
await
this
.
spider
.
execute
();
}
}
}
}
...
...
test.js
View file @
0f13c593
const
Promise
=
require
(
'bluebird'
);
const
Promise
=
require
(
'bluebird'
);
const
redis
=
require
(
"redis"
);
// const redis = require("redis");
const
client
=
redis
.
createClient
();
// const client = redis.createClient();
const
Horseman
=
require
(
'node-horseman'
);
// const Horseman = require('node-horseman');
Promise
.
promisifyAll
(
require
(
"redis"
));
// Promise.promisifyAll(require("redis"));
const
fs
=
require
(
'fs'
);
// 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'
);
// const config = require('config');
async
function
t
()
{
// async function t () {
return
't'
;
// return 't';
}
// }
const
DI
=
require
(
'./lib/DI'
);
// const DI = require('./lib/DI');
const
logger
=
DI
.
getLogger
();
// const logger = DI.getLogger();
//
try
{
//
}
catch
(
e
)
{
// // new Buffer('hnmz147852.').toString('base64')
}
// // new Buffer('Q2hlY2hlbmcyMzUj', 'base64').toString();
return
//
// let i = 0;
// new Buffer('hnmz147852.').toString('base64')
// async function test (l) {
// new Buffer('Q2hlY2hlbmcyMzUj', 'base64').toString();
// i += 1;
// await Promise.delay(l*1000).then(async function() {
let
i
=
0
;
// logger.info('过了' + l + '秒');
async
function
test
(
l
)
{
// logger.info((new Date()).toLocaleString());
i
+=
1
;
// logger.info('=======================================');
await
Promise
.
delay
(
l
*
1000
).
then
(
async
function
()
{
// if (i < 8) {
logger
.
info
(
'过了'
+
l
+
'秒'
);
// await test(1);
logger
.
info
((
new
Date
()).
toLocaleString
());
// } else {
logger
.
info
(
'======================================='
);
// return true;
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'));
// 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}`);
// // }
// });
// 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));
// });
// });
// }
//
//
// (async () => {
//
//
//
//
//
//
// return;
// const readline = require('readline');
// await test(1);
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
//
// 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;
// return;
//
//
// got(url, {
// const mt = await t();
// headers: {
// console.log(mt);
// 'Cookie': a
// 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');
// }
// }
// }).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;
// return;
//
// let info = 'showCusDetailWithId("302761")';
// const updatedAt = moment().format('YYYY-MM-DD HH:mm:ss');
// var m = info.match(/showCusDetailWithId\("(\d*)"\)/);
// console.log(moment('2017-08-09 09:56').format('X'));
// console.log(m);
// return;
// return;
// class AppError extends Error {
// constructor (message, status) {
//
//
//
// Calling parent constructor of base Error class.
//
console.log(config.get('clueInputType')['dealer.autohome']);
//
super(message)
;
//
return
;
//
//
// // Capturing stack trace, excluding constructor call from it.
// // best
// Error.captureStackTrace(this, this.constructor);
// // 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.
// // use args, use toString in class
// this.name = this.constructor.name;
// (function () {
// console.log('Welcome to the Internet. Please follow me.');
// }());
//
//
//
// You can use any additional properties you want.
//
console.log(moment().add(1, 'days').toString());
//
// I'm going to use preferred HTTP status for this error types.
//
console.log(moment().toString());
//
// `500` is the default value if not specified.
//
throw '1';
//
this.status = status || 500
;
//
return
;
//
//
// }
// console.log(fs.existsSync('/tmp/a') && fs.statSync('/tmp/a').isFile());
// };
// return;
// class AppError extends Error {
// constructor(message) {
// super(message);
// this.message = message;
// // this.name = 'MyError';
// this.name = this.constructor.name;
// }
// }
//
//
// class BError extends AppError {
// // console.log(moment().subtract(30, 'days').format('YYYY.MM.DD'));
// constructor (fields) {
// // return;
// // 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);
// }
//
//
// }
// // const cookie = require('cookie');
// // console.log(cookie.serialize('foo', 'bar'));
// // return;
//
//
// // const getCookies = async () => {
// response{status:success, message, name:}
// // const client = await redis.createClient();
// responseError
// // const cookies_key = 'autohome_cookies';
// function peg$computePosDetails() {
// // let cookies = JSON.parse(await client.getAsync(cookies_key));
// throw new BError('语法错误', 'idsssss');
// // 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 {
// // let info = 'showCusDetailWithId("302761")';
// peg$computePosDetails();
// // var m = info.match(/showCusDetailWithId\("(\d*)"\)/);
// } catch (e) {
// // console.log(m);
// console.log(e);
// // return;
// };
//
// 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);
// console.log('难道是这里?');
// })
// // .catch(Horseman.TimeoutError, function(e) {
// // console.log('等待超时');
// // console.log(e);
// // console.log((new Date()).toLocaleString());
// // })
// .close();
// }
const
testHorseman
=
async
()
=>
{
function
promise
(){
const
horseman
=
new
Horseman
();
return
Promise
.
delay
(
1000
).
then
(
function
()
{
await
console
.
log
(
'111111'
,
new
Date
());
horseman
})
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
}
.
viewport
(
1920
,
1080
)
async
function
test
()
{
.
open
(
'https://www.zhihu.com/'
)
await
promise
()
.
then
(()
=>
{
console
.
log
(
'222222'
,
new
Date
());
console
.
log
((
new
Date
()).
toLocaleString
());
}
})
(
async
()
=>
{
.
waitForSelector
(
'.subtitle'
,
{
timeout
:
2000
})
await
test
().
then
(
async
()
=>
{
.
screenshot
(
'zhihu.png'
)
await
Promise
.
delay
(
1000
);
.
error
(
function
(
e
)
{
console
.
log
(
'3333333'
,
new
Date
());
console
.
error
(
"这是一个错误: "
,
e
);
});
})
})()
.
catch
(
function
(
e
)
{
\ No newline at end of file
console
.
log
(
e
);
console
.
log
(
'难道是这里?'
);
})
// .catch(Horseman.TimeoutError, function(e) {
// console.log('等待超时');
// console.log(e);
// console.log((new Date()).toLocaleString());
// })
.
close
();
}
\ 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