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
3068ec8c
authored
Sep 01, 2017
by
马玮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change random api
parent
e14bd056
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
13 deletions
+17
-13
lib/spider/dealer/Autohome.js
+3
-4
lib/spider/dealer/Easypass.js
+4
-5
lib/utils/lodash.js
+4
-3
test.js
+6
-1
No files found.
lib/spider/dealer/Autohome.js
View file @
3068ec8c
...
...
@@ -6,7 +6,6 @@ const config = require('config');
const
cheerio
=
require
(
'cheerio'
);
const
Horseman
=
require
(
'node-horseman'
);
const
moment
=
require
(
'moment'
);
var
randomInt
=
require
(
'random-int'
);
const
axios
=
require
(
'axios'
);
// 自定义模块
const
_
=
require
(
'../../utils/lodash'
);
...
...
@@ -27,7 +26,7 @@ class Autohome extends Base {
async
tryLogin
()
{
// 随机返回登录状态
// return [new errors.TryLoginError('登录失效'),
randomInt
(0, 1)];
// return [new errors.TryLoginError('登录失效'),
_.random
(0, 1)];
try
{
let
newCookies
;
let
oldCookies
;
...
...
@@ -79,7 +78,7 @@ class Autohome extends Base {
async
login
()
{
// 随机返回登录状态
// return [new errors.LoginError('登录失败'),
randomInt
(0, 1)];
// return [new errors.LoginError('登录失败'),
_.random
(0, 1)];
try
{
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 开始表单登录`
);
...
...
@@ -292,7 +291,7 @@ class Autohome extends Base {
// 判断是否抓取完全
if
(
customerIndex
<
rowCount
)
{
let
randomSecs
=
randomInt
(
1
,
5
);
let
randomSecs
=
_
.
random
(
1
,
5
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 随机等待
${
randomSecs
}
秒`
);
await
Promise
.
delay
(
randomSecs
*
1000
).
then
(
async
function
()
{
params
.
pageIndex
+=
1
;
...
...
lib/spider/dealer/Easypass.js
View file @
3068ec8c
...
...
@@ -6,7 +6,6 @@ const config = require('config');
const
cheerio
=
require
(
'cheerio'
);
const
Horseman
=
require
(
'node-horseman'
);
const
moment
=
require
(
'moment'
);
var
randomInt
=
require
(
'random-int'
);
const
axios
=
require
(
'axios'
);
// 自定义模块
const
_
=
require
(
'../../utils/lodash'
);
...
...
@@ -28,7 +27,7 @@ class Easypass extends Base {
async
tryLogin
()
{
// 随机返回登录状态
// return [new errors.TryLoginError('登录失效'),
randomInt
(0, 1)];
// return [new errors.TryLoginError('登录失效'),
_.random
(0, 1)];
let
newCookies
;
let
oldCookies
;
let
loginStatus
=
false
;
...
...
@@ -77,8 +76,8 @@ class Easypass extends Base {
async
login
()
{
// 随机返回登录状态
// return
randomInt
(0, 1);
// return [new errors.LoginError('登录失败'),
randomInt
(0, 1)];
// return
_.random
(0, 1);
// return [new errors.LoginError('登录失败'),
_.random
(0, 1)];
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 开始表单登录`
);
const
username
=
this
.
params
.
username
;
...
...
@@ -295,7 +294,7 @@ class Easypass extends Base {
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/nextPage.png`
);
}
let
randomSecs
=
randomInt
(
1
,
5
);
let
randomSecs
=
_
.
random
(
1
,
5
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 随机等待
${
randomSecs
}
秒`
);
await
Promise
.
delay
(
randomSecs
*
1000
).
then
(
async
function
()
{
await
fetchByPage
();
...
...
lib/utils/lodash.js
View file @
3068ec8c
'use strict'
;
exports
.
pick
=
require
(
'lodash.pick'
);
exports
.
assign
=
require
(
'lodash.assign'
);
\ No newline at end of file
exports
.
pick
=
require
(
'lodash/pick'
);
exports
.
assign
=
require
(
'lodash/assign'
);
exports
.
random
=
require
(
'lodash/random'
);
\ No newline at end of file
test.js
View file @
3068ec8c
const
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./lib/utils'
);
const
utils
=
require
(
'./lib/utils'
);
const
_
=
require
(
'./lib/utils/lodash'
);
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
_
.
random
(
1
,
5
));
console
.
log
(
utils
.
md5
(
'欢迎来到王者荣耀'
));
return
;
// const DI = require('./lib/DI');
// process.env.NODE_ENV = process.env.NODE_ENV || 'production';
// process.env.NODE_CONFIG_DIR = __dirname + '/config';
...
...
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