0

I have watched the video on youtube then I want to practice the code in a different way. I want to extract the data from imdbdata website then how to resolve the issue JS code.

Getting data from IMDB website

    const option = {
        uri: "https://www.imdb.com/chart/moviemeter/?ref_=nv_mv_mpm",
        headers: {
            Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "en-US,en;q=0.5",
        },
        json: true,
        transform: (body) => cheerio.load(body),
    };

request-promise code

    await rp(option)
        .then(($) => {
            process.stdout.write("loading...\n");
            let table = [];
            $("tbody[class='lister-list'] tr").each((i, el) => {
                //self call function
                process.stdout.write(`.`);
                let link =
                    "https://www.imdb.com" +
                    $(el).find("td[class='titleColumn'] a").attr("href");
                goToNextPage(link, table);
            });
            console.table(table);
        })
        .catch((e) => console.log(e));

I have called the function goToNextPage from request-promise JS code with parameters

const goToNextPage = (link, table) => {
    let $ = cheerio.load(link);
    let title = $("div[class='title_wrapper'] > h1").text().trim(),
        ratingValue = $("div[class='ratingValue'] > strong > span")
            .text()
            .trim(),
        director = $("div[class='credit_summary_item'] > a")
            .first()
            .text()
            .trim(),
        filmType = $("div[class='subtext'] > a")
            .not('a[title="See more release dates"]')
            .text()
            .replace(/([A-Z])/g, " $1")
            .trim();
    table.push({
        title,
        director,
        filmType,
        ratingValue,
    });
};

Why does output is only empty data showing from the console.table(table)

Malik
  • 1
  • 1

1 Answers1

0

Your code generates the dots with:

process.stdout.write(`.`); 

Remove that part of code and you won't have dots.

Skatt
  • 372
  • 3
  • 10