Commit 5428dec9 by 马玮

Add getHeaderCookie

parent 2a7e029e
......@@ -43,5 +43,5 @@ sudo yum install redis
- [ ] 优化:进程Graceful Stop
- [ ] 优化:统一所有代码let和const的使用风格
- [x] 重构:使用ES7语法重构代码
- [ ] 重构:创建Spider基类复用代码(setCookies|getCookies|getHeaderCookies)
- [x] 重构:创建Spider基类复用代码(setCookies|getCookies|getHeaderCookie)
- [ ] 重构:使用import|export写法增加模块读取速度
......@@ -19,6 +19,21 @@ class DealerHelper {
}
}
static async getHeaderCookie(params) {
try {
const cookies = await DealerHelper.getCookies(params);
const cookieStrs = [];
cookies.forEach((cookie) => {
cookieStrs.push(`${cookie.name}=${cookie.value}`);
});
return cookieStrs.join(';');
} catch (e) {
return null;
}
}
static async saveCookies(params) {
try {
// 延长过期时间为一个月后
......
......@@ -187,15 +187,7 @@ class AutoHome {
return;
}
const cookies = await DealerHelper.getCookies(this.params);
// console.log(JSON.stringify(cookies));return;
const cookieArray = [];
cookies.forEach((cookie) => {
cookieArray.push(`${cookie.name}=${cookie.value}`);
});
const cookieStr = cookieArray.join(';');
const headerCookie = await DealerHelper.getHeaderCookie(this.params);
let rowcount;
let customerIndex = 0;
......@@ -227,7 +219,7 @@ class AutoHome {
axios.get('http://ics.autohome.com.cn/Dms/Order/SearchOrderList', {
params: params,
headers:{
Cookie: cookieStr
Cookie: headerCookie
}
}).then(async res => {
const clueData = res.data;
......
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