Add screen

This commit is contained in:
AMAICDAX 2025-09-10 11:25:43 +02:00
parent 01d79c06da
commit ffbf63a15d

View file

@ -91,60 +91,50 @@ const getUserProfile = async (req, res) => {
}
};
const scrapeLinkedInProfile = async (profileUrl) => {
const scrapeLinkedInProfile = async (profileUrl, email, password) => {
console.log("Scraping LinkedIn profile:", profileUrl);
const browser = await chromium.launch({
headless: true, // headless mode pour serveur
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await browser.newPage();
// 1. Login
try {
// === 1. Login ===
await page.goto("https://www.linkedin.com/login", {
waitUntil: "domcontentloaded",
waitUntil: "networkidle",
timeout: 60000,
});
console.log("Login page loaded");
await page.screenshot({ path: "step1_login.png", fullPage: true });
await page.fill("#username", email, { delay: 50 });
await page.fill("#password", password, { delay: 50 });
await Promise.all([
page.click('[type="submit"]'),
page.waitForNavigation({ waitUntil: "domcontentloaded", timeout: 60000 }),
page.waitForNavigation({ waitUntil: "networkidle", timeout: 60000 }),
]);
console.log("Logged in");
await page.screenshot({ path: "step2_logged_in.png", fullPage: true });
// Aller sur le profil et attendre le contenu
// === 2. Aller sur le profil ===
await page.goto(profileUrl, {
waitUntil: "domcontentloaded",
waitUntil: "networkidle",
timeout: 60000,
});
await page.waitForSelector("h1", { timeout: 60000 });
console.log("Profile page loaded");
await page.screenshot({ path: "step3_profile_loaded.png", fullPage: true });
// Scroll pour charger lazy sections
// Scroll pour charger contenu lazy
await page.evaluate(() => window.scrollBy(0, window.innerHeight));
await page.waitForTimeout(2000);
await page.screenshot({ path: "step4_scrolled.png", fullPage: true });
// 2. Aller sur le profil
await page.goto(profileUrl, {
waitUntil: "domcontentloaded",
timeout: 60000,
});
// Aller sur le profil et attendre le contenu
await page.goto(profileUrl, {
waitUntil: "domcontentloaded",
timeout: 60000,
});
await page.waitForSelector("h1", { timeout: 60000 });
// Scroll pour charger lazy sections
await page.evaluate(() => window.scrollBy(0, window.innerHeight));
await page.waitForTimeout(2000);
// 3. Extraire infos
// === 3. Extraire les infos ===
const profileData = await page.evaluate(() => {
const getText = (selector) =>
document.querySelector(selector)?.innerText || null;
@ -166,8 +156,18 @@ const scrapeLinkedInProfile = async (profileUrl) => {
};
});
await page.screenshot({ path: "step5_data_extracted.png", fullPage: true });
console.log("Data extracted:", profileData);
await browser.close();
return profileData;
} catch (err) {
console.error("❌ Erreur pendant le scraping:", err.message);
await page.screenshot({ path: "error.png", fullPage: true });
await browser.close();
throw err;
}
};
module.exports = {