Skip to content

Commit 7d5c2bc

Browse files
committed
info scraping string function added
1 parent a1271d9 commit 7d5c2bc

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ example object:
2727
title: 'Batman – One Dark Knight #3 (2022)',
2828
description: 'From the sewers under Gotham to the roiling waters of the harbor, Batman’s march toward Blackgate Prison is nearing its end…but far from being a passive prisoner, E.M.P. has his own mission to fulfill—and there’s no way he’s letting the Dark Knight stop him from carrying it out!',
2929
coverPage: 'https://i0.wp.com/getcomics.info/share/uploads/2022/07/Batman-One-Dark-Knight-3-2022.jpg?fit=400%2C512&ssl=1',
30-
info: [ ' Image Format : JPG ', ' Year : 2022 ', ' Size : 277 MB' ],
30+
info: {
31+
ImageFormat: 'JPG',
32+
Year: '2022',
33+
Size: '634 MB'
34+
},
3135
downloadLinks: [
3236
[Object], [Object],
3337
[Object], [Object],

functions/infoScraper.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.infoScraper = (str) => {
2+
const string2 = str.split(",");
3+
const string3 = string2.map(x =>
4+
x.split(":")
5+
);
6+
7+
const infoObj = {};
8+
for(let i in string3) {
9+
infoObj[ string3[ i ][ 0 ].replace(`'`, ``).trim().split(" ").join("") ] = string3[ i ][ 1 ].replace(`'`, ``).trim();
10+
}
11+
12+
return infoObj;
13+
};

functions/parentScraper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const cheerio = require('cheerio');
22
const axios = require('axios');
33

4+
const { infoScraper } = require('./infoScraper');
5+
46
exports.parentScraper = (uri, page) => {
57

68
return new Promise((resolve, reject) => {
@@ -32,7 +34,9 @@ exports.parentScraper = (uri, page) => {
3234
const title = $('.post-info').find('h1').text().trim();
3335
const description = $('.post-contents').find('p').first().children().remove().end().text().trim();
3436
const infoArr = $('.post-contents > p:nth-child(7)').text().split("|");
35-
const info = infoArr.splice(1, 3).join();
37+
const infoStr = infoArr.splice(1, 3).join();
38+
39+
const info = infoScraper(infoStr);
3640

3741
$('.aio-pulse').each(function() {
3842
const downloadLinks = $(this).children('a').attr('href');

0 commit comments

Comments
 (0)