roflmuffin / node-anime-scraper

Scrapes information from Gogoanime to get Anime, Episode & Video information & urls.
59 stars 17 forks source link

TypeError: Cannot read property 'parent' of undefined #8

Closed rerz closed 7 years ago

rerz commented 8 years ago
var animeutils = require("anime-scraper").AnimeUtils;
var anime = require("anime-scraper").Anime;
var cloudscraper = require("cloudscraper");

cloudscraper.get("http://kissanime.com", function(err, body, response)
{
    var cookiestring = response.request.headers.cookie;
    animeutils.setSessionCookie(cookiestring);

    console.log("Got the cookie!");

    animeutils.searchByName("").then(function(results){
        console.log("Got all anime!");
        var animes = results;

        animes.forEach(function(item)
        {
            anime.fromUrl(item.url);
            console.log("Instantiated anime object for anime " + item.name);
        });
    });
});

Above you can see my code, I am getting all of the anime on kissanime and instantiate an object for all of them, at the end of the list I get this exception:

/home/ubuntu/workspace/node_modules/anime-scraper/node_modules/cheerio/lib/parse.js:55
    var oldParent = node.parent || node.root,
                        ^
TypeError: Cannot read property 'parent' of undefined
    at Function.exports.update (/home/ubuntu/workspace/node_modules/anime-scraper/node_modules/cheerio/lib/parse.js:55:25)
    at module.exports (/home/ubuntu/workspace/node_modules/anime-scraper/node_modules/cheerio/lib/parse.js:17:11)
    at Function.exports.load (/home/ubuntu/workspace/node_modules/anime-scraper/node_modules/cheerio/lib/static.js:19:14)
    at Anime.fromUrl (/home/ubuntu/workspace/node_modules/anime-scraper/lib/index.js:274:21)
    at ClientRequest.<anonymous> (/home/ubuntu/workspace/node_modules/anime-scraper/node_modules/got/index.js:177:4)
    at ClientRequest.g (events.js:180:16)
    at ClientRequest.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1552:9)
    at Socket.emit (events.js:95:17)
    at Socket._destroy.self._writableState.errorEmitted (net.js:441:14)
roflmuffin commented 8 years ago

It could be possible that one of the Anime pages has different syntax to the rest or has differing content which would cause this issue. I would advise adding a catch block to it to catch this error and continue.

I will work on adding better error handling.

hutber commented 7 years ago

👍 I'm also getting the exact same error

roflmuffin commented 7 years ago

@jamiehutber Can you send me the code you are running that is triggering that error?

hutber commented 7 years ago

Hey pal. I actually found 2 things. I wasn't using this repo and I was too overzealous in replying :) Secondly it was as you suggested. I had opened to many concurrent connections that was throwing this error up.

So in other words, I do believe you can close this and thoroughly ignore me lol