MonkeyAndres / animeflv-scrapper

🏯 AnimeFLV fake API made scrapping the AnimeFLV website
https://www.npmjs.com/package/animeflv-scrapper
GNU General Public License v3.0
14 stars 10 forks source link

codigo para obtener toda la informacion de todos los animes #13

Open rebox1000 opened 3 years ago

rebox1000 commented 3 years ago

Hola, soy nuevo en node.js y este codigo no me funciona alguien sabe ¿ Por que ?

api.getAllAnimes().then((animes) => {
          for (let i = 0; i < animes.length; i++) {
              api.getAnimeInfo(animes[i].title).then((info) => {
                  console.log(info)
              })
          }  
})

Tambien probe este codigo y manda el mismo error:

const animes = await api.getAllAnimes();
   for (let i = 0; i < animes.length; i++) {
       const animeinfo = await api.getAnimeInfo(animes[i].title)
        console.log(animeinfo)
    }
/var/www/html/Anime-Api/node_modules/animeflv-scrapper/lib/selectors.js:6
var imageElement=dom.querySelectorAll(".Image img")[i];var image=imageElement.attributes.src||"https://animeflv.net".concat(imageElement.attributes["data-cfsrc"]);var label=element.querySelector(".Title").innerHTML;var type=element.querySelector(".Image span.Type").innerHTML;return{link:link,title:title,image:image,label:label,type:type}}};var extractAnimeList=function extractAnimeList(dom){var animeElements=dom.querySelectorAll(".Anime");return toArray(animeElements).map(formatAnimeList(dom))};var extractAnimeGenres=function extractAnimeGenres(dom){var genresElements=dom.querySelectorAll(".Nvgnrs a");return toArray(genresElements).map(function(element){return element.innerHTML})};var extractAnimeBasicInfo=function extractAnimeBasicInfo(dom){var animeBasicInfo=extractVariableValue(dom,"var anime_info")||"[]";var _JSON$parse=JSON.parse(animeBasicInfo),_JSON$parse2=(0,_slicedToArray2["default"])(_JSON$parse,3),index=_JSON$parse2[0],label=_JSON$parse2[1],title=_JSON$parse2[2];return{index:index,label:label,title:title}};var extractAnimeDetails=function extractAnimeDetails(dom){var animeBasicInfo=extractAnimeBasicInfo(dom);return _objectSpread(_objectSpread({},animeBasicInfo),{},{rate:dom.querySelector("#votes_prmd").innerHTML,votes:dom.querySelector("#votes_nmbr").innerHTML,genres:extractAnimeGenres(dom),description:dom.querySelector(".Description p").innerHTML.trim(),episodes:extractEpisodes(dom)})};var extractVideoSources=function extractVideoSources(dom){var videosRAW=extractVariableValue(dom,"var videos")||"{}";var _JSON$parse3=JSON.parse(videosRAW),videos=_JSON$parse3.SUB;var videoSources=videos.map(function(item){return item.code});var downloadLink=extractDownloadLink(videos);return{videos:videoSources,downloads:downloadLink}};var extractDownloadLink=function extractDownloadLink(videos){var downloadLink=videos.find(function(item){return item.server==="mega"});return downloadLink!==undefined?downloadLink.url:""};var extractLatestEpisodes=function extractLatestEpisodes(dom){var latestEpisodes=dom.querySelectorAll(".ListEpisodios li");return latestEpisodes.map(function(element){var _element$querySelecto=element.querySelector("a").getAttribute("href").split("/"),_element$querySelecto2=(0,_slicedToArray2["default"])(_element$querySelecto,3),title=_element$querySelecto2[2];var previewSrc=element.querySelector("img").getAttribute("src");return{title:title,label:element.querySelector(".Title").text,episode:element.querySelector(".Capi").text,image:previewSrc?"".concat(baseURL).concat(previewSrc):null}})};module.exports={parseHTML:parseHTML,extractAnimeDetails:extractAnimeDetails,extractAnimeList:extractAnimeList,extractVideoSources:extractVideoSources,extractLatestEpisodes:extractLatestEpisodes};

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at extractAnimeBasicInfo (/var/www/html/Anime-Api/node_modules/animeflv-scrapper/lib/selectors.js:6:842)
    at extractAnimeDetails (/var/www/html/Anime-Api/node_modules/animeflv-scrapper/lib/selectors.js:6:1111)
    at _callee4$ (/var/www/html/Anime-Api/node_modules/animeflv-scrapper/lib/api.js:1:3906)
    at tryCatch (/var/www/html/Anime-Api/node_modules/regenerator-runtime/runtime.js:63:40)
    at Generator.invoke [as _invoke] (/var/www/html/Anime-Api/node_modules/regenerator-runtime/runtime.js:293:22)
    at Generator.next (/var/www/html/Anime-Api/node_modules/regenerator-runtime/runtime.js:118:21)
    at asyncGeneratorStep (/var/www/html/Anime-Api/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/var/www/html/Anime-Api/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

Otras veces me da este error:

node:internal/process/promises:245
          triggerUncaughtException(err, true /* fromPromise */);
          ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
  code: 'ERR_UNHANDLED_REJECTION'