brazilian-courts-scrappers
Version:
Data scrapper para fazer raspagem de dados de processos judiciais dos portais de tribunais do Brasil.
125 lines • 7.03 kB
JavaScript
;
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"));
const utils_1 = require("../utils");
class Pje1gTjbaParteScrapper extends PartesScrapper_1.default {
constructor(macroContainer) {
super(macroContainer);
this.macroContainer = macroContainer;
}
fetchParticipantesInfo() {
return super.fetchParticipantesInfo();
}
loadPageCheckpoints() {
const partesContainers = this.macroContainer.querySelectorAll(".is-item-pilha-parte");
const poloAtivoWrapper = Array.from(partesContainers).filter(container => container
.querySelector(".polo")
.textContent.trim()
.toLowerCase()
.includes(utils_1.trtInterfacePolosNames.ativo));
const poloPassivoWrapper = Array.from(partesContainers).filter(container => container
.querySelector(".polo")
.textContent.trim()
.toLowerCase()
.includes(utils_1.trtInterfacePolosNames.passivo));
const poloOutrosWrapper = Array.from(partesContainers).filter(container => container
.querySelector(".polo")
.textContent.trim()
.toLowerCase()
.includes(utils_1.trtInterfacePolosNames.outros));
const polos = [poloAtivoWrapper, poloPassivoWrapper, poloOutrosWrapper];
const [poloAtivoContainer, poloPassivoContainer, outrosContainer] = polos.map(poloWrapper => {
return poloWrapper.length == 0
? null
: poloWrapper[0].querySelector("pje-parte-processo > section");
});
this.poloAtivoContainer = poloAtivoContainer;
this.poloPassivoContainer = poloPassivoContainer;
this.outrosContainer = outrosContainer;
}
getPartes() {
const poloAtivo = this.getCompletePolo(this.poloAtivoContainer, "autor");
const poloPassivo = this.getCompletePolo(this.poloPassivoContainer, "reu");
const outros = this.getCompletePolo(this.outrosContainer, "outros");
return { poloAtivo, poloPassivo, outros };
}
getCompletePolo(partesWrapper, tipoDeParte) {
if (!partesWrapper)
return [];
const partes = [];
partesWrapper.querySelectorAll(":scope > ul").forEach(item => {
const nome = item
.querySelector("pje-nome-parte")
.textContent.trim()
.toUpperCase();
const until3Wrappers = item.firstElementChild.querySelectorAll(":scope > span.ng-star-inserted");
const { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj, email, endereco } = this.getInfoFromPje1gTrt5Wrappers(until3Wrappers);
const advogados = this.getAdvogados(item.querySelectorAll(".partes-representante"));
partes.push(new ScrappedParte_1.default(nome, tipoDeParte, dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj, undefined, endereco, email, undefined, undefined, advogados));
});
return partes;
}
getInfoFromPje1gTrt5Wrappers(until3Wrappers) {
var _a, _b, _c, _d;
const cpfCnpjWrapperArray = Array.from(until3Wrappers).filter(wrapper => { var _a; return (_a = wrapper.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase().startsWith("cpf:"); });
const emailWrapperArray = Array.from(until3Wrappers).filter(wrapper => { var _a; return (_a = wrapper.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase().startsWith("(email:"); });
const addressWrapperArray = Array.from(until3Wrappers).filter(wrapper => {
var _a, _b;
return !((_a = wrapper.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase().startsWith("cpf:")) &&
!((_b = wrapper.textContent) === null || _b === void 0 ? void 0 : _b.trim().toLowerCase().startsWith("(email:"));
});
const { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj } = this.getCpfCnpjInfo(cpfCnpjWrapperArray);
const emailRegexMatch = emailWrapperArray.length
? (_a = emailWrapperArray[0].textContent) === null || _a === void 0 ? void 0 : _a.match(utils_1.EMAIL_REGEX)
: "";
const email = emailRegexMatch ? (_b = emailRegexMatch[0]) !== null && _b !== void 0 ? _b : "" : "";
const endereco = addressWrapperArray.length
? (_d = (_c = addressWrapperArray[0].textContent) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : ""
: "";
return { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj, email, endereco };
}
getCpfCnpjInfo(wrapperArray) {
const dontHaveCpfCnpj = !wrapperArray.length;
const noCpfCnpjReason = wrapperArray.length ? "" : "Não cadastrado no PJe";
let cpf = "", cnpj = "";
if (wrapperArray.length) {
const onlyNumbersCpfCnpj = wrapperArray[0].textContent.replaceAll(/[^\d]/g, "");
if (onlyNumbersCpfCnpj.length === 11)
cpf = onlyNumbersCpfCnpj;
if (onlyNumbersCpfCnpj.length === 14)
cnpj = onlyNumbersCpfCnpj;
}
return { dontHaveCpfCnpj, noCpfCnpjReason, cpf, cnpj };
}
getAdvogados(advsWrapper) {
return Array.from(advsWrapper).map(advWrapper => {
const name = this.getAdvogadoName(advWrapper);
const infoTexts = Array.from(advWrapper.querySelectorAll("span.span-informacao")).map(span => { var _a; return (_a = span.textContent) !== null && _a !== void 0 ? _a : ""; });
const { cpf, oab, email } = this.getAdvogadoInfo(infoTexts);
return new ScrappedParte_1.default(name, "advogado contrário", false, undefined, cpf, undefined, undefined, undefined, email, undefined, oab);
});
}
getAdvogadoName(advWrapper) {
const nameStr = advWrapper
.querySelector("span:not(.ng-star-inserted)")
.textContent.toUpperCase();
return nameStr.replace("(ADVOGADO)", "").trim();
}
getAdvogadoInfo(array) {
const cpfArray = array.find(str => str.toLowerCase().includes("(cpf:"));
const oabArray = array.find(str => str.includes("(OAB:"));
const emailArray = array.find(str => { var _a; return (_a = str.match(utils_1.EMAIL_REGEX)) !== null && _a !== void 0 ? _a : false; });
const cpf = cpfArray ? cpfArray[0].replaceAll(/[^\d]/g, "") : "";
const oab = oabArray
? oabArray[0].replace("(OAB:", "").replace(")", "").trim()
: "";
const email = emailArray ? emailArray[0].match(utils_1.EMAIL_REGEX)[0] : "";
return { cpf, oab, email };
}
}
exports.default = Pje1gTjbaParteScrapper;
//# sourceMappingURL=Pje1gTrt5PartesScrapper.js.map