Skip to content

Commit

Permalink
Fixed premature end of work
Browse files Browse the repository at this point in the history
  • Loading branch information
safonovpro committed Sep 18, 2018
1 parent c19b24c commit e8ca4b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Crawler extends EventEmitter {
if(result.statusCode === 200 && /^text\/html/.test(result.headers['content-type'])) {
this._getDataByUrl(currentUrl, 'GET')
.then(result => {
this._generateEvents('data', {currentUrl, result});

for(let link of result.links) {
if(link.url) this.crawl(link.url);
}

this._generateEvents('data', {currentUrl, result});
}).catch(error => {
this._generateEvents('error', {currentUrl, error});
});
Expand All @@ -51,11 +51,11 @@ class Crawler extends EventEmitter {

result.links.push({href: location, url: nextUrl});

this._generateEvents('data', {currentUrl, result});

if(nextUrl) {
this.crawl(nextUrl, ++countOfRedirects);
}

this._generateEvents('data', {currentUrl, result});
} else {
this._generateEvents('data', {currentUrl, result});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-html-crawler",
"version": "1.0.5",
"version": "1.0.6",
"description": "Crawler (spider) of site web pages by domain name",
"main": "crawler.js",
"scripts": {
Expand Down

0 comments on commit e8ca4b3

Please sign in to comment.