Skip to content

Commit

Permalink
added try{}catch(_){}
Browse files Browse the repository at this point in the history
  • Loading branch information
sujalgoel committed Jun 15, 2021
1 parent 7c08968 commit 8477410
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 20 additions & 4 deletions src/mdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 8477410

Please sign in to comment.