...
|
...
|
@@ -224,6 +224,19 @@ const writeFile = (file, str) => { |
|
|
* @type {{getKeyWordsUrl}}
|
|
|
*/
|
|
|
|
|
|
const getRedisKeywords2 = (start, end) => {
|
|
|
return redis.lrangeAsync(redisKey.keywordsList, start, end).then(res => {
|
|
|
return _.map(res, (elem) => {
|
|
|
return elem.replace('keywords_mana:', '');
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 查询 redis中 关键词
|
|
|
* @type {{getKeyWordsUrl}}
|
|
|
*/
|
|
|
|
|
|
const getRedisKeywords = (start, end) => {
|
|
|
return redis.lrangeAsync(redisKey.keywordsList, start, end).then(res => {
|
|
|
let urls = {pc: [], wap: []};
|
...
|
...
|
@@ -317,29 +330,47 @@ const rpKeyWordsUrl = (url) => { |
|
|
};
|
|
|
|
|
|
const visitKeyWordsUrl = () => {
|
|
|
let size = 2;
|
|
|
let size = 5;
|
|
|
let currentPage = 1;
|
|
|
|
|
|
return redis.hgetAsync('yohoSeo', 'rpPage').then(page => {
|
|
|
page = page || 1;
|
|
|
|
|
|
setInterval(() => {
|
|
|
let intval = setInterval(() => {
|
|
|
currentPage = page;
|
|
|
return redis.hsetAsync('yohoSeo', 'rpPage', page++).then(() => {
|
|
|
return util.sleep(100);
|
|
|
}).then(() => {
|
|
|
return getRedisKeywords((currentPage - 1) * size, currentPage * size - 1);
|
|
|
return getRedisKeywords2((currentPage - 1) * size, currentPage * size - 1);
|
|
|
}).then(d => {
|
|
|
let ddata = Object.assign([], _.map(d.pc, function(dd) {
|
|
|
return rpKeyWordsUrl(dd);
|
|
|
}));
|
|
|
let ddata = [];
|
|
|
let buff;
|
|
|
|
|
|
if (d.length <= 0) {
|
|
|
clearInterval(intval);
|
|
|
return this.redis.hset('yohoSeo', 'rpPage', 1).then(() => {
|
|
|
return [];
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(d, keyword => {
|
|
|
buff = new Buffer(keyword).toString('hex').toUpperCase();
|
|
|
|
|
|
// TODO 纪录已经推送的关键词
|
|
|
ddata.push(
|
|
|
rpKeyWordsUrl(`https://www1.yohobuy.com/so/${buff}.html`),
|
|
|
rpKeyWordsUrl(`https://www2.yohobuy.com/so/${buff}.html`),
|
|
|
rpKeyWordsUrl(`https://m1.yohobuy.com/so/${buff}.html`),
|
|
|
rpKeyWordsUrl(`https://m2.yohobuy.com/so/${buff}.html`)
|
|
|
);
|
|
|
});
|
|
|
|
|
|
return Promise.all(ddata);
|
|
|
}).then(d => {
|
|
|
console.log(`rpKeyWordsUrl => page: ${page}, result: ${JSON.stringify(d)}`);
|
|
|
return d;
|
|
|
});
|
|
|
}, 1000);
|
|
|
}, 200);
|
|
|
|
|
|
return page;
|
|
|
});
|
...
|
...
|
|