Readme

Getting all boxes from MinhaBibliotecaCatolica.com.br

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
export const webscrapeMinhaBibliotecaCatolicaBoxList = (async () => {
const sourceUrl =
"https://assine.bibliotecacatolica.com.br/edicoes-anteriores";
const { default: cheerio } = await import("npm:cheerio");
const html = await fetchText(sourceUrl);
console.log(cheerio);
const $ = cheerio.load(html);
const result = [];
$(".top_card").each((_, topCard) => {
// box info
const box = $(".tag_card span", topCard).first().text().trim();
const boxInfo = {
number: parseInt(/Box\s+(\d+)/gm.exec(box)[1], 10),
month: /^(\w+)/gm.exec(box)[1],
year: 2018 + Math.trunc(parseInt(/Box\s+(\d+)/gm.exec(box)[1], 10) / 12),
title: /(Box \d+)/gm.exec(box)[1],
};
result.push({
title: $(".title_card", topCard).first().text().trim(),
boxInfo,
thumbnailUrl: $(".tumbnail_card", topCard).attr("src"),
description: $(".description_card", topCard).first().text().trim(),
});
});
return result.sort((a, b) => {
if (a.boxInfo.number < b.boxInfo.number)
return -1;
if (a.boxInfo.number > b.boxInfo.number)
return 1;
return 0;
});
})();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023