我正在努力为所有的教授抓取http://www.ratemyprofessors.com/。我的代码似乎得到了以下错误:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [node]
2: 0x10d3f9c [node]
3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
5: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
6: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
7: 0x292aec062bf
Aborted我不知道我做了什么导致这个错误,但它可能是因为我的循环?我需要循环超过1000万页,但我不知道为什么它会给我这个错误,只有10个循环。代码如下:
var express = require('express');
var path = require('path');
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var app = express();
var count = 1;
var url;
while(count != 10){
url = "http://www.ratemyprofessors.com/ShowRatings.jsp?tid=" + count;
request(url, function(err, resp, body){
var $ = cheerio.load(body);
if($('.error').text().substring(0, 14) == "Page Not Found"){
console.log("hello");
count++;
return;
}else{
console.log($('.error').text().substring(0, 14) );
var pfname = $('.pfname');
var plname = $('.plname');
var professorName = pfname.text().replace(/\s/g, '') + " " +plname.text().replace(/\s/g, '');
console.log(professorName);
console.log(url);
count++;
}
return;
})
}
app.listen(3000, function(){
console.log("server is now listening");
})https://stackoverflow.com/questions/47480525
复制相似问题