Files
old-web/app/crawler/crawl.js

38 lines
916 B
JavaScript
Raw Normal View History

"use strict";
/*
Entry point for crawling functionality
All communication between crawlers and savers is here
All environment specific configuration is read here and
passed to the crawlers and savers.
*/
const OlxCrawler = require("./specific/olx");
2019-09-18 15:32:48 +02:00
const { OLX_CONFIG } = require("./crawlerConfig");
const PostgresSaver = require("./savers/postgres");
2019-09-18 15:32:48 +02:00
const crawlers = [
new OlxCrawler(
[new PostgresSaver()],
OLX_CONFIG.OLX_CRAWLER_AD_TYPE,
OLX_CONFIG.OLX_CRAWLER_AD_CATEGORIES,
OLX_CONFIG.OLX_MAX_PAGES,
OLX_CONFIG.OLX_MAX_RESULTS_PER_PAGE,
OLX_CONFIG.OLX_IGNORED_USERNAMES,
OLX_CONFIG.OLX_DELAY_BETWEEN_PAGES
2019-09-18 15:32:48 +02:00
)
];
async function crawlAll() {
for (let crawler of crawlers) {
try {
return await crawler.crawl();
} catch (e) {
console.log("Error crawling. Trying next crawler! ", e);
return [];
}
}
}
module.exports = {
crawlAll
};