asyncfunctionstart() { for (let i = 0; i < 50; i++) { let res = await runHelper(spider(i)); if (res) { console.log(i, res.name); // 方便观察进度 joke = joke.concat(res); } } upload(joke); // 上传数据库 }
asyncfunctionspider(page) { let currentUrl = url + page; let html = await fetch(currentUrl).then(res => res.text()); let $ = cheerio.load(html); let ls = $('.j-r-list>ul>li'); let data = []; ls.map((i, item) => { let avatar = $(item).find('img').attr('data-original'); let name = $(item).find('.u-user-name').text(); let joke = $(item).find('.j-r-list-c-desc a').text(); data.push({ name, avatar, joke }); }); return data; }