Showing
1 changed file
with
38 additions
and
7 deletions
@@ -224,6 +224,19 @@ const writeFile = (file, str) => { | @@ -224,6 +224,19 @@ const writeFile = (file, str) => { | ||
224 | * @type {{getKeyWordsUrl}} | 224 | * @type {{getKeyWordsUrl}} |
225 | */ | 225 | */ |
226 | 226 | ||
227 | +const getRedisKeywords2 = (start, end) => { | ||
228 | + return redis.lrangeAsync(redisKey.keywordsList, start, end).then(res => { | ||
229 | + return _.map(res, (elem) => { | ||
230 | + return elem.replace('keywords_mana:', ''); | ||
231 | + }); | ||
232 | + }); | ||
233 | +}; | ||
234 | + | ||
235 | +/** | ||
236 | + * 查询 redis中 关键词 | ||
237 | + * @type {{getKeyWordsUrl}} | ||
238 | + */ | ||
239 | + | ||
227 | const getRedisKeywords = (start, end) => { | 240 | const getRedisKeywords = (start, end) => { |
228 | return redis.lrangeAsync(redisKey.keywordsList, start, end).then(res => { | 241 | return redis.lrangeAsync(redisKey.keywordsList, start, end).then(res => { |
229 | let urls = {pc: [], wap: []}; | 242 | let urls = {pc: [], wap: []}; |
@@ -317,29 +330,47 @@ const rpKeyWordsUrl = (url) => { | @@ -317,29 +330,47 @@ const rpKeyWordsUrl = (url) => { | ||
317 | }; | 330 | }; |
318 | 331 | ||
319 | const visitKeyWordsUrl = () => { | 332 | const visitKeyWordsUrl = () => { |
320 | - let size = 2; | 333 | + let size = 5; |
321 | let currentPage = 1; | 334 | let currentPage = 1; |
322 | 335 | ||
323 | return redis.hgetAsync('yohoSeo', 'rpPage').then(page => { | 336 | return redis.hgetAsync('yohoSeo', 'rpPage').then(page => { |
324 | page = page || 1; | 337 | page = page || 1; |
325 | 338 | ||
326 | - setInterval(() => { | 339 | + let intval = setInterval(() => { |
327 | currentPage = page; | 340 | currentPage = page; |
328 | return redis.hsetAsync('yohoSeo', 'rpPage', page++).then(() => { | 341 | return redis.hsetAsync('yohoSeo', 'rpPage', page++).then(() => { |
329 | return util.sleep(100); | 342 | return util.sleep(100); |
330 | }).then(() => { | 343 | }).then(() => { |
331 | - return getRedisKeywords((currentPage - 1) * size, currentPage * size - 1); | 344 | + return getRedisKeywords2((currentPage - 1) * size, currentPage * size - 1); |
332 | }).then(d => { | 345 | }).then(d => { |
333 | - let ddata = Object.assign([], _.map(d.pc, function(dd) { | ||
334 | - return rpKeyWordsUrl(dd); | ||
335 | - })); | 346 | + let ddata = []; |
347 | + let buff; | ||
348 | + | ||
349 | + if (d.length <= 0) { | ||
350 | + clearInterval(intval); | ||
351 | + return this.redis.hset('yohoSeo', 'rpPage', 1).then(() => { | ||
352 | + return []; | ||
353 | + }); | ||
354 | + } | ||
355 | + | ||
356 | + _.forEach(d, keyword => { | ||
357 | + buff = new Buffer(keyword).toString('hex').toUpperCase(); | ||
358 | + | ||
359 | + // TODO 纪录已经推送的关键词 | ||
360 | + ddata.push( | ||
361 | + rpKeyWordsUrl(`https://www1.yohobuy.com/so/${buff}.html`), | ||
362 | + rpKeyWordsUrl(`https://www2.yohobuy.com/so/${buff}.html`), | ||
363 | + rpKeyWordsUrl(`https://m1.yohobuy.com/so/${buff}.html`), | ||
364 | + rpKeyWordsUrl(`https://m2.yohobuy.com/so/${buff}.html`) | ||
365 | + ); | ||
366 | + }); | ||
336 | 367 | ||
337 | return Promise.all(ddata); | 368 | return Promise.all(ddata); |
338 | }).then(d => { | 369 | }).then(d => { |
339 | console.log(`rpKeyWordsUrl => page: ${page}, result: ${JSON.stringify(d)}`); | 370 | console.log(`rpKeyWordsUrl => page: ${page}, result: ${JSON.stringify(d)}`); |
340 | return d; | 371 | return d; |
341 | }); | 372 | }); |
342 | - }, 1000); | 373 | + }, 200); |
343 | 374 | ||
344 | return page; | 375 | return page; |
345 | }); | 376 | }); |
-
Please register or login to post a comment