首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cheerio web抓取错误

Cheerio web抓取错误
EN

Stack Overflow用户
提问于 2017-11-25 06:03:50
回答 0查看 584关注 0票数 1

我正在努力为所有的教授抓取http://www.ratemyprofessors.com/。我的代码似乎得到了以下错误:

代码语言:javascript
复制
    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个循环。代码如下:

代码语言:javascript
复制
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");
})
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47480525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档