Recommand · October 22, 2021 0

Evaluation failed: TypeError: Cannot read properties of undefined (reading 'content') on a vps

Hello I do a parser in pupperterJs
All work fine on localhost but
when i go on my vps
and i launch the scrapper on this i got this problem

Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'content')
    at __puppeteer_evaluation_script__:5:77
    at ExecutionContext._evaluateInternal (/home/bboymond/backVostFree-Extension/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async ExecutionContext.evaluate (/home/bboymond/backVostFree-Extension/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16)
    at async Anime.getAnimeById (/home/bboymond/backVostFree-Extension/node_modules/vostfreescrapper/lib/Anime.js:64:23)
    at async /home/bboymond/backVostFree-Extension/routes/animes.js:4:9

I doesn’t understand why i have this error on my vps and not on my computer

Function of parsing

async getAnimeById(animeId) {
        await this.vsf.relocatePage(`${animeId}-ddl-streaming-1fichier-uptobox.html`)
        await this.vsf.page.exposeFunction('getLecteur', this.utils.getLecteur);
        const anime = await this.vsf.page.evaluate(async () => {
            const anime = {};
            anime.url = document.location.href;
            anime.title = document.querySelector('h1').innerText;
            anime.description = document.getElementsByName('description')[0].content;
            const image =  document.querySelector('.slide-poster')
            anime.image = image.querySelectorAll('img')[0].src
            anime.nbepisodes = parseInt(document.getElementsByClassName('year')[0].innerText.replace('Episode ', ''));
            anime.genres = [];
            const genres = document.getElementsByClassName('right')[0];
            genres.querySelectorAll('a').forEach(element => {
                anime.genres.push(element.innerText);
            });
            FinalPlayer = [];
            const allPlayer = document.querySelectorAll('.player_box');
            for (const element of allPlayer) {
                let player = element.id.replace('content_', '');
                const stream = document.getElementById(player);
                if (stream) {
                    const meth = stream.className;    
                    const id = element.textContent;
                    const link = await getLecteur(meth, id);
                    FinalPlayer.push({player:player, link: link});
                }
            }
            anime.episodes = [];
            const button = document.querySelectorAll('.button_box');
            button.forEach(element => {
                const id = element.id.replace('buttons_', '');
                const data = element.querySelectorAll('div');
                let link = [];
                data.forEach(elem => {
                    for (const player of FinalPlayer) {
                        if (elem.id === player.player) {
                            link.push(player.link);
                        }
                    }
                });
                anime.episodes.push({id: id, link: link});
            });

            return anime;
        });
        return anime;
    } 

Function for create page and relocated

async initPage() {
        this.browser = await puppeteer.launch();
        this.page = await this.browser.newPage();
        await this.page.setDefaultNavigationTimeout(0);
    }

    async closePage() {
        await this.browser.close();
    }

    async relocatePage(endpoint) {
        await this.page.goto(this.baseUrl + endpoint);
    }

I supposed the problem come from page loading but i’m not sure about that

the url of test was
this.baseUrl = ‘https://vostfree.tv/’;
and the end id can be 616 for exemple