![]() 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.quebec/public_html/scripts/ |
const fs = require('fs');
const path = require('path');
const cheerio = require('cheerio');
function slugify(str) {
return str
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
}
const destDir = path.join(__dirname, '../public/images/lawyers');
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
async function downloadImage(url, dest) {
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to fetch ${url}`);
const fileStream = fs.createWriteStream(dest);
await new Promise((resolve, reject) => {
res.body.pipe(fileStream);
res.body.on('error', reject);
fileStream.on('finish', resolve);
});
}
(async () => {
const url = 'https://www.adwavocats.com/a-propos/';
const html = await fetch(url).then(r => r.text());
const $ = cheerio.load(html);
const images = [];
// Find all team member blocks (look for <img> tags with team member photos)
$('img').each((i, el) => {
const src = $(el).attr('src');
const alt = $(el).attr('alt') || '';
// Only consider images from uploads/2022/09 or uploads/ (profile photos)
if (src && /uploads\//.test(src) && !/logo|icon|default|signature|osmose/i.test(src)) {
// Try to get the name from alt, fallback to filename
let name = alt.trim();
if (!name || name.length < 3) {
name = path.basename(src).replace(/\.[a-z0-9]+$/i, '').replace(/-/g, ' ');
}
images.push({
name: slugify(name),
url: src.startsWith('http') ? src : 'https://www.adwavocats.com' + src,
ext: path.extname(src).replace('.', '')
});
}
});
// Remove duplicates by name
const unique = {};
images.forEach(img => { unique[img.name] = img; });
const finalImages = Object.values(unique);
let success = 0, failed = 0;
for (const img of finalImages) {
const dest = path.join(destDir, `${img.name}.${img.ext}`);
if (fs.existsSync(dest)) {
console.log(`${img.name}.${img.ext} already exists, skipping.`);
continue;
}
try {
await downloadImage(img.url, dest);
console.log(`Downloaded: ${img.name}.${img.ext}`);
success++;
} catch (e) {
console.log(`Failed: ${img.name}.${img.ext} (${img.url})`);
failed++;
}
}
console.log(`\nDownload complete. Success: ${success}, Failed: ${failed}`);
})();