brazilian-courts-scrappers
Version:
Data scrapper para fazer raspagem de dados de processos judiciais dos portais de tribunais do Brasil.
118 lines • 6.19 kB
JavaScript
"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 utils_1 = require("../utils");
const PartesScrapper_1 = __importDefault(require("./PartesScrapper"));
class ProjudiTjbaPartesScrapper extends PartesScrapper_1.default {
constructor(macroContainer) {
super(macroContainer);
this.macroContainer = macroContainer;
}
fetchParticipantesInfo() {
return super.fetchParticipantesInfo();
}
loadPageCheckpoints() {
const querySelectors = {
autores: "#Partes > table > tbody > tr:nth-child(2) > td:nth-child(2)",
reus: "#Partes > table > tbody > tr:nth-child(3) > td:nth-child(2)",
testemunhas: "#Partes > table > tbody > tr:nth-child(4) > td:nth-child(2)",
terceiros: "#Partes > table > tbody > tr:nth-child(5) > td:nth-child(2)",
};
this.poloAtivoWrapperTd = this.macroContainer.querySelector(querySelectors.autores);
this.poloPassivoWrapperTd = this.macroContainer.querySelector(querySelectors.reus);
this.testemunhasWrapperTd = this.macroContainer.querySelector(querySelectors.testemunhas);
this.terceirosWrapperTd = this.macroContainer.querySelector(querySelectors.terceiros);
}
getPartes() {
const poloAtivo = this.getCompletePolo(this.poloAtivoWrapperTd, "autor");
const poloPassivo = this.getCompletePolo(this.poloPassivoWrapperTd, "reu");
const testemunhas = this.getCompletePolo(this.testemunhasWrapperTd, "testemunha");
const terceiros = this.getCompletePolo(this.terceirosWrapperTd, "terceiro");
const outros = testemunhas.concat(terceiros);
return { poloAtivo, poloPassivo, outros };
}
getCompletePolo(poloWrapperTd, tipoDeParte) {
const partesTbody = poloWrapperTd.querySelector(":scope table.tabelaLista[id^=tabelaPartes] > tbody");
return Array.from(partesTbody.querySelectorAll(":scope > tr[id]:not([id^=trAdv])")).map(tr => {
return this.getParte(poloWrapperTd, tr, tipoDeParte);
});
}
getParte(poloWrapperTd, tr, tipoDeParte) {
const name = tr.querySelector("td:nth-child(2)").textContent.trim();
const cpfCnpjStr = tr
.querySelector("td:nth-child(4)")
.textContent.trim();
const { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj } = this.getCpfCnpjFromString(cpfCnpjStr);
const judSystemId = tr.id.replace("tr", "");
const { address, email, phone } = this.getParteContatos(poloWrapperTd, judSystemId);
const advogados = this.getParteAdvogados(poloWrapperTd, judSystemId);
return new ScrappedParte_1.default(name, tipoDeParte, dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj, judSystemId, address, email, phone, undefined, advogados);
}
getCpfCnpjFromString(cpfCnpj) {
cpfCnpj = cpfCnpj.split("\n")[0];
const dontHaveCpfCnpj = cpfCnpj.toLowerCase() === "não cadastrado";
const noCpfCnpjReason = cpfCnpj.toLowerCase() === "não cadastrado"
? "Não cadastrado no Projudi"
: "";
const cpf = !cpfCnpj.includes("/") ? cpfCnpj.trim() : "";
const cnpj = cpfCnpj.includes("/") ? cpfCnpj.trim() : "";
return { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj };
}
getParteContatos(poloWrapperTd, parteJudSystemId) {
const contactsTbodySelector = `table.tabelaLista ~ span[id^="spanEnd${parteJudSystemId}"] table > tbody`;
const contactsTbody = poloWrapperTd.querySelector(contactsTbodySelector);
let contactInfo = contactsTbody.querySelector("tr:nth-child(2) > td").textContent;
contactInfo = contactInfo
.replaceAll(String.fromCharCode(10), "")
.replaceAll(/\s+/g, " ")
.trim();
return this.parseContactInfo(contactInfo);
}
parseContactInfo(contactInfo) {
let baseStr = contactInfo;
const email = this.getEmail(contactInfo);
if (email)
baseStr = baseStr.replace(email, "");
const phoneWithTag = this.getPhoneWithTag(contactInfo);
const phone = phoneWithTag
? phoneWithTag.replace(/(\()|(Contato: )|(\))/g, "")
: "";
if (phoneWithTag)
baseStr = baseStr.replace(phoneWithTag, "");
const address = (0, utils_1.extendedTrim)(baseStr, [","]);
return { address, email, phone };
}
getEmail(str) {
const emailRegex = /[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*/;
const result = str.match(emailRegex);
return result ? result[0].toLowerCase() : "";
}
getPhoneWithTag(str) {
const phoneRegex = /\(Contato: \+?[0-9 ]{10,}\)/;
const result = str.match(phoneRegex);
return result ? result[0] : "";
}
getParteAdvogados(partesWrapperTd, parteJudSystemId) {
const advogadosTbody = partesWrapperTd.querySelector(`table.tabelaLista ~ span[id^="spanAdv${parteJudSystemId}"] table[id^="tabelaAdvogadoPartes"] > tbody`);
const advogadosTrs = advogadosTbody.querySelectorAll('tr[class]:not([class="ultimaLinha"])');
return Array.from(advogadosTrs).map(tr => {
const nomeCpfString = tr
.querySelector("td:nth-child(1)")
.textContent.trim();
const oabString = tr
.querySelector("td:nth-child(2)")
.textContent.trim();
const nomeCpf = nomeCpfString.split(" (CPF:");
nomeCpf[1] = nomeCpf[1] ? nomeCpf[1].replace(")", "") : "";
const name = nomeCpf[0];
const cpf = nomeCpf[1];
const oab = oabString;
return new ScrappedParte_1.default(name, "advogado contrário", false, undefined, cpf, undefined, undefined, undefined, undefined, undefined, oab, undefined);
});
}
}
exports.default = ProjudiTjbaPartesScrapper;
//# sourceMappingURL=ProjudiTjbaPartesScrapper.js.map