UNPKG

b3_insigths

Version:
44 lines 1.46 kB
import { load } from "cheerio"; export default class VariableIncomeScraper { BASE_URL = "https://statusinvest.com.br"; typePath; constructor(type) { switch (type) { case "stock": this.typePath = "/acoes"; break; case "reit": this.typePath = "/fundos-imobiliarios"; break; case "index": this.typePath = "/indices"; break; } } async getPageHTML(option) { const headers = new Headers({ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0" }); const response = await fetch(`${this.BASE_URL}${this.typePath}/${option}`, { headers }); const html = await response.text(); return html; } async getValue(option) { const html = await this.getPageHTML(option); const $ = load(html); if (this.isNotFoundPage($)) { this.handleNotFoundPage(); } const price = $(".value", ".special").text(); return `R$${price}`; } isNotFoundPage($) { const notFoundBear = $(".mascote", ""); return notFoundBear.length > 0; } handleNotFoundPage() { console.log("Ativo não encontrado."); process.exit(0); } } //# sourceMappingURL=VariableIncomeScraper.js.map