working on crawler

This commit is contained in:
Nedim Uka
2019-06-13 15:49:31 +02:00
parent fdd0124924
commit 6aaaea1612
2 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
const fetch = require('node-fetch');
const cheerio = require('cheerio');
export default class OlxCrawler {
constructor(fromPage = 0, toPage = 10, maxResults = 1000) {
this.fromPage = fromPage;
this.toPage = toPage;
this.maxResults = maxResults;
}
async sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async indexPages(start, end, maxResults = 1000) {
let results = {};
for (let i = start; i <= end; i++) {
let result = await this.indexPage(i, maxResults);
Object.assign(results, result)
await this.sleep(5000);
}
return results;
}
async crawl() {
let results = await this.indexPages(this.fromPage, this.toPage, this.maxResults);
return results;
}
}