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
c7b520f9
authored
Aug 25, 2017
by
马玮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update .gitignore
parent
a9233a5a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
33 deletions
+39
-33
.gitignore
+2
-0
lib/spider/dealer/Autohome.js
+37
-33
No files found.
.gitignore
View file @
c7b520f9
!/tmp/workflow
/tmp/captcha/*
/tmp/captcha/*
/tmp/workflow/*
/tmp/workflow/*
/logs/dealer/*
/logs/dealer/*
\ No newline at end of file
lib/spider/dealer/Autohome.js
View file @
c7b520f9
...
@@ -48,44 +48,48 @@ class Autohome extends Base {
...
@@ -48,44 +48,48 @@ class Autohome extends Base {
async
tryLogin
()
{
async
tryLogin
()
{
// 随机返回登录状态
// 随机返回登录状态
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
// return [new errors.TryLoginError('登录失效'), randomInt(0, 1)];
let
newCookies
;
let
oldCookies
;
let
loginStatus
=
false
;
try
{
try
{
oldCookies
=
await
DealerHelper
.
getCookies
(
this
.
params
);
let
newCookies
;
}
catch
(
e
)
{
let
oldCookies
;
logger
.
debug
(
`accountID:
${
this
.
params
.
accountID
}
, 没有cookies:
${
e
}
`
);
let
loginStatus
=
false
;
}
if
(
oldCookies
)
{
try
{
const
horseman
=
new
Horseman
({
oldCookies
=
await
DealerHelper
.
getCookies
(
this
.
params
);
ignoreSSLErrors
:
true
}
catch
(
e
)
{
});
logger
.
debug
(
`accountID:
${
this
.
params
.
accountID
}
, 没有cookies:
${
e
}
`
);
}
loginStatus
=
await
horseman
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
.
viewport
(
1920
,
1080
)
.
cookies
(
oldCookies
)
.
open
(
'http://ics.Autohome.com.cn/passport/Home/Index'
)
.
screenshot
(
'tmp/workflow/autohome/tryLogin.png'
)
.
exists
(
'#loginout'
);
newCookies
=
await
horseman
.
cookies
();
await
horseman
.
close
();
}
if
(
loginStatus
)
{
if
(
oldCookies
)
{
const
params
=
this
.
params
;
const
horseman
=
new
Horseman
({
params
.
cookies
=
newCookies
;
ignoreSSLErrors
:
true
});
logger
.
debug
(
`accountID:
${
this
.
params
.
accountID
}
, cookies:
${
JSON
.
stringify
(
newCookies
)}
`
);
loginStatus
=
await
horseman
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
.
viewport
(
1920
,
1080
)
.
cookies
(
oldCookies
)
.
open
(
'http://ics.Autohome.com.cn/passport/Home/Index'
)
.
screenshot
(
'tmp/workflow/autohome/tryLogin.png'
)
.
exists
(
'#loginout'
);
newCookies
=
await
horseman
.
cookies
();
await
horseman
.
close
();
}
if
(
loginStatus
)
{
const
params
=
this
.
params
;
params
.
cookies
=
newCookies
;
logger
.
debug
(
`accountID:
${
this
.
params
.
accountID
}
, cookies:
${
JSON
.
stringify
(
newCookies
)}
`
);
await
DealerHelper
.
saveCookies
(
params
);
return
1
;
}
else
{
throw
new
errors
.
TryLoginError
(
'登录失效'
);
}
}
catch
(
e
)
{
await
DealerHelper
.
saveCookies
(
params
);
return
1
;
}
else
{
throw
new
errors
.
TryLoginError
(
'登录失效'
);
}
}
}
}
...
...
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