From 847741028a8ba3573b5f067e3c2652e1b17af5f7 Mon Sep 17 00:00:00 2001 From: sujal-ops-cyber <67121014+sujal-ops-cyber@users.noreply.github.com> Date: Tue, 15 Jun 2021 12:29:48 +0530 Subject: [PATCH] added try{}catch(_){} --- package.json | 2 +- src/mdl.js | 24 ++++++++++++++++++++---- test/test.js | 12 ++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index bd7b671..cf21f72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mdl-scraper", - "version": "1.0.1", + "version": "1.0.2", "description": "A npm package for scraping data from mydramalist", "main": "index.js", "scripts": { diff --git a/src/mdl.js b/src/mdl.js index 3bfaeeb..173b01c 100644 --- a/src/mdl.js +++ b/src/mdl.js @@ -18,10 +18,26 @@ module.exports = { if ($(e).attr('id')) { r.mdl_id = $(e).attr('id'); r.title = title.text().trim(); - r.ranking = $(e).find('div[class="ranking pull-right"]').find('span').text(); - r.type = $(e).find('span[class="text-muted"]').text().split('-')[0].trim(); - r.year = $(e).find('span[class="text-muted"]').text().split('-')[1].split(',')[0].trim(); - r.series = $(e).find('span[class="text-muted"]').text().split('-')[1].split(',')[1].trim(); + if ($(e).find('div[class="ranking pull-right"]').find('span').text()) { + r.ranking = $(e).find('div[class="ranking pull-right"]').find('span').text(); + } else { + r.ranking = null; + } + try { + r.type = $(e).find('span[class="text-muted"]').text().split('-')[0].trim(); + } catch (_) { + r.type = null; + } + try { + r.year = $(e).find('span[class="text-muted"]').text().split('-')[1].split(',')[0].trim(); + } catch (_) { + r.year = null; + } + try { + r.series = $(e).find('span[class="text-muted"]').text().split('-')[1].split(',')[1].trim(); + } catch (_) { + r.series = null; + } return dramas.push(r); } r.name = title.text().trim(); diff --git a/test/test.js b/test/test.js index 39cfd32..a1408e3 100644 --- a/test/test.js +++ b/test/test.js @@ -1,12 +1,12 @@ const { mdl } = require('../index'); -mdl.SearchQuery('song-joong-ki') - .then((data) => { - console.log('SearchQuery Example:'); - console.log(data); - }); +// mdl.SearchQuery('aloners') +// .then((data) => { +// console.log('SearchQuery Example:'); +// console.log(data); +// }); -mdl.FetchQuery('61371-vincenz') +mdl.FetchQuery('696359-people-living-alone') .then((data) => { console.log('FetchQuery Example:'); console.log(data);