![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.ca/private_html/scripts/ |
const fetch = require('node-fetch');
const cheerio = require('cheerio');
if (process.argv.length < 3) {
console.error('Usage: node fetch_barreau_lawyer.js "First Last"');
process.exit(1);
}
const lawyerName = process.argv.slice(2).join(' ');
const searchUrl = `https://www.barreau.qc.ca/fr/trouver-un-avocat/resultats/?n=${encodeURIComponent(lawyerName)}`;
(async () => {
// 1. Fetch search results page
const res = await fetch(searchUrl);
const html = await res.text();
const $ = cheerio.load(html);
// 2. Find all profile links for the name
const profileLinks = [];
$('a').each((i, el) => {
const href = $(el).attr('href');
const text = $(el).text().trim();
if (href && href.startsWith('/fr/trouver-un-avocat/membre/?id=') && text.toLowerCase().includes(lawyerName.toLowerCase().split(' ')[0])) {
profileLinks.push('https://www.barreau.qc.ca' + href);
}
});
if (profileLinks.length === 0) {
console.log('No lawyer found for', lawyerName);
return;
}
// 3. For each profile, fetch and extract info
const results = [];
for (const url of profileLinks) {
const res2 = await fetch(url);
const html2 = await res2.text();
const $$ = cheerio.load(html2);
const getText = (selector) => $$(selector).text().trim();
const getList = (selector) => $$(selector).map((i, el) => $$(el).text().trim()).get();
const name = $$("h1").first().text().trim();
const employer = $$("strong:contains('Société / employeur')").parent().text().replace('Société / employeur', '').trim();
const addressBlock = $$("strong:contains('Adresse')").parent().text().replace('Adresse', '').trim();
const phone = $$("strong:contains('Téléphone')").parent().text().replace('Téléphone', '').trim();
const fax = $$("strong:contains('Télécopieur')").parent().text().replace('Télécopieur', '').trim();
const email = $$("strong:contains('Courriel')").parent().text().replace('Courriel', '').trim();
const domaines = getList("ul:contains('Domaines de droit') li");
const langues = getList("ul:contains('Langues parlées') li");
const annee = $$("strong:contains('Année de première inscription')").parent().text().replace("Année de première inscription au Tableau de l'Ordre", '').trim();
const section = $$("strong:contains('Barreau de section')").parent().text().replace('Barreau de section', '').trim();
const mandats = getList("ul:contains('Types de mandats acceptés') li");
results.push({
url,
name,
employer,
address: addressBlock,
phone,
fax,
email,
domaines,
langues,
annee,
section,
mandats
});
}
console.log(JSON.stringify(results, null, 2));
})();