CTK-WARRIOR / ctk-anime-scraper

scraper to scrap anime from gogoanime
12 stars 2 forks source link

getPopularAnime function lmao? #1

Closed PaimonWheeWhee closed 3 years ago

PaimonWheeWhee commented 3 years ago

lmfao so since you already have a getRecentAnime function, couldn't you just change the base URL and fetch the animes from a differnt link? This would be an example for a getPopularAnime function, this is just theoretical of course :D

const cheerio = require("cheerio");
const axios = require("axios");
const baseURL = "https://gogoanime.ai/popular.html"
const getPopularAnime = async () => {
  try {
    let data = await axios({url: baseURL})
    data = data.data;
    let popularAnime = []

    let $ = cheerio.load(data);
    $('ul.items li').each(function (i, elem) {
      $ = cheerio.load($(this).html())
      let object = {}
      object.title = $('p.name a').text() || null
      object.episode = $('p.episode').text() || null
      object.image = $('div.img img').attr("src") || null
      object.link = $('div.img a').attr("href") || null
      if (object.link) object.link = baseURL + object.link;
      popularAnime.push(object) 
    })

    return popularAnime;
  } catch (err) {
    throw err;
  }
}

module.exports = getPopularAnime;
CTK-WARRIOR commented 3 years ago

i guess you are right

PaimonWheeWhee commented 3 years ago

Add it to the package :DDDDD

CTK-WARRIOR commented 3 years ago

ok

PaimonWheeWhee commented 3 years ago

Thank you <3