The purpose of the below program is to crawl CNN, and write all its text to a single file (using couple of third parties)
I get
RangeError: Maximum call stack size exceeded
How to troubleshoot this, and how can I bypass that? is there a way I can "free" memory ? and how?
//----------Configuration--------------
var startingUrl = "http://cnn.com"; //keep the http\https or www prefix
var crawlingDepth = "50";
var outputFileName = "cnn.txt";
//-------------------------------------
var Crawler = require("js-crawler");
var sanitizeHtml = require('sanitize-html');
var htmlToText = require('html-to-text');
var fs = require('fs');
var index = 0;
new Crawler().configure({depth: crawlingDepth})
.crawl(startingUrl, function onSuccess(page) {
var text = htmlToText.fromString(page.body, {
wordwrap: false,
hideLinkHrefIfSameAsText: true,
ignoreHref: true,
ignoreImage: true
});
index++;
console.log(index + " pages were crawled");
fs.appendFile(outputFileName, text, function (err) {
if (err) {
console.log(err);
};
console.log('It\'s saved! in same location.');
});
});