Skip to content

Commit

Permalink
fix: errors while doc request (ignore docs in 'request' handler)
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Apr 21, 2020
1 parent 0e71bf1 commit dc0f4b6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ module.exports = async (baseUrl, options = {}) => {
return request.abort();
}

if (SKIP_IMAGES && request.resourceType() == 'image') {
const isDoc = options.docsExtensions.some(ext => request.url().includes(`.${ext}`));
if(isDoc) {
// досюда как-то доходит
request.abort();
} else if (SKIP_IMAGES && request.resourceType() == 'image') {
request.abort();
} else if (SKIP_CSS && request.resourceType() == 'stylesheet') {
request.abort();
Expand All @@ -238,12 +242,16 @@ module.exports = async (baseUrl, options = {}) => {
}
});

page.on('error', function(err) {
console.error('${color.red}Page error:${color.reset} ' + err.toString());
});

// костыль, который возвращает фейково обойдённый документ, если он признан документом
// нужно, чтобы доки не сканировались (выдают ошибку), но при этом добавлялись в csv
// т.к. в этом контексте нет текущего урла, он задаётся в глобал через событие requeststarted
const isDoc = options.docsExtensions.some(ext => currentUrl.includes(`.${ext}`));
if (isDoc) {
return {
return{
options: {},
depth: 0,
previousUrl: '',
Expand Down Expand Up @@ -315,10 +323,11 @@ module.exports = async (baseUrl, options = {}) => {
});
await crawler.queue(baseUrl);
await crawler.onIdle();
await crawler.close();

// after scan
const t = Math.round((Date.now() - start) / 1000);
const perPage = Math.round((t / requestedCount) * 100) / 100;
await crawler.close();

const finishScan = () => {
if(options.removeCsv) {
Expand Down

0 comments on commit dc0f4b6

Please sign in to comment.