Skip to content

Commit

Permalink
feat: progress, show page count, time per page
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Mar 5, 2020
1 parent b310334 commit b6aa6f4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ module.exports = async (baseUrl, options) => {
console.log(`Scrapping ${baseUrl}...`);

const crawler = await HCCrawler.launch(crawlerOptions);
let pagesCount = 1;
crawler.on('requeststarted', options => {
currentUrl = options.url;
if (DEBUG) console.log(`request ${options.url}`);
if (DEBUG) console.log(`${pagesCount} ${options.url}`);
pagesCount++;
});
await crawler.queue(baseUrl);
await crawler.onIdle();

const t = Math.round((Date.now() - start) / 1000);
console.log(`Finish: ${t} sec`);
const perPage = Math.round(t / pagesCount * 100) / 100;
console.log(`Finish: ${t} sec (${perPage} per page)`);
await crawler.close();
};

0 comments on commit b6aa6f4

Please sign in to comment.