UNPKG

brazilian-courts-scrappers

Version:

Data scrapper para fazer raspagem de dados de processos judiciais dos portais de tribunais do Brasil.

94 lines 4.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ScrappedParte_1 = __importDefault(require("../data-structures/ScrappedParte")); const PartesScrapper_1 = __importDefault(require("./PartesScrapper")); class Pje1gTjbaParteScrapper extends PartesScrapper_1.default { constructor(macroContainer) { super(macroContainer); this.macroContainer = macroContainer; } fetchParticipantesInfo() { return super.fetchParticipantesInfo(); } loadPageCheckpoints() { this.divPoloAtivoTbody = this.macroContainer.querySelector("#poloAtivo > table > tbody"); this.divPoloPassivoTbody = this.macroContainer.querySelector("#poloPassivo > table > tbody"); } getPartes() { const poloAtivo = this.getPartesWithoutEnderecos(this.divPoloAtivoTbody, "autor"); const poloPassivo = this.getPartesWithoutEnderecos(this.divPoloPassivoTbody, "reu"); const outros = []; return { poloAtivo, poloPassivo, outros }; } getPartesWithoutEnderecos(tbody, tipoDeParte) { const partes = []; tbody.querySelectorAll(":scope > tr").forEach(tr => { const parteString = tr .querySelector("td:nth-child(1) > span:nth-child(1) > span") .textContent.trim(); const name = this.getNameFromPje1gTjbaParteString(parteString); const cpfCnpjStr = this.getCpfCnpjFromPje1gTjbaParteString(parteString); const { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj } = this.getParteCpfCnpjFromString(cpfCnpjStr); const advogados = this.getParteAdvogados(tr); const parte = new ScrappedParte_1.default(name, tipoDeParte, dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj, undefined, undefined, undefined, undefined, undefined, advogados); partes.push(parte); }); return partes; } getNameFromPje1gTjbaParteString(parteStr) { const stringWithoutParteType = parteStr .replace(/ \([A-Za-z]*\)$/, "") .trim(); const nameWithoutCpfCnpj = stringWithoutParteType .replace(/(CPF: \d{3}\x2E\d{3}\x2E\d{3}\x2D\d{2})|(CNPJ: \d{2}.\d{3}.\d{3}\/\d{4}-\d{2})$/, "") .replace(/ - $/, ""); const nameWithoutOab = nameWithoutCpfCnpj .replace(Pje1gTjbaParteScrapper.PJE1GTJBA_OAB_REGEX, "") .replace(/ - $/, ""); return nameWithoutOab; } getCpfCnpjFromPje1gTjbaParteString(parteStr) { const cpfCnpj = parteStr.match(/(\d{3}\x2E\d{3}\x2E\d{3}\x2D\d{2})|(\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})/); return cpfCnpj ? cpfCnpj[0] : ""; } getOabFromPje1gTjbaParteString(parteStr) { const oab = parteStr.match(Pje1gTjbaParteScrapper.PJE1GTJBA_OAB_REGEX); if (!oab) return ""; return oab[0].replace("OAB ", ""); } getParteCpfCnpjFromString(cpfCnpj) { cpfCnpj = cpfCnpj.trim(); const dontHaveCpfCnpj = !cpfCnpj; const noCpfCnpjReason = cpfCnpj ? "" : "Não cadastrado no PJe"; const dashDotSlashStrippedString = cpfCnpj.replaceAll(/[^\d]/g, ""); const cpf = dashDotSlashStrippedString.length === 11 ? dashDotSlashStrippedString : ""; const cnpj = dashDotSlashStrippedString.length === 14 ? dashDotSlashStrippedString : ""; return { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj }; } getParteAdvogados(parteWrapperTr) { const advogadosLists = parteWrapperTr.querySelectorAll(":scope > td > ul"); const advogadosLis = Array.from(advogadosLists) .map(ulList => ulList.querySelectorAll(":scope > li")) .flat()[0]; return Array.from(advogadosLis).map(li => { const advString = li .querySelector(":scope > small > span > span") .textContent.trim(); const name = this.getNameFromPje1gTjbaParteString(advString); const cpf = this.getCpfCnpjFromPje1gTjbaParteString(advString); const oab = this.getOabFromPje1gTjbaParteString(advString); return new ScrappedParte_1.default(name, "advogado contrário", false, undefined, cpf, undefined, undefined, undefined, undefined, undefined, oab); }); } } Pje1gTjbaParteScrapper.PJE1GTJBA_OAB_REGEX = /OAB [A-Z]{2}\d{4,}/; exports.default = Pje1gTjbaParteScrapper; //# sourceMappingURL=Pje1gTjbaPartesScrapper.js.map