From 9d6d51451bf19c09c4be05a52eb1e37cffcfc43f Mon Sep 17 00:00:00 2001 From: AMAICDAX Date: Tue, 9 Sep 2025 16:21:15 +0200 Subject: [PATCH] modif --- controllers/linkedin.js | 43 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/controllers/linkedin.js b/controllers/linkedin.js index 6c19562..1125ea7 100644 --- a/controllers/linkedin.js +++ b/controllers/linkedin.js @@ -2,7 +2,7 @@ const axios = require("axios"); const querystring = require("querystring"); -const puppeteer = require("puppeteer"); +const { chromium } = require("playwright"); const clientId = "780w7gsy8eysmj"; const clientSecret = "WPL_AP1.w6OTTkAndAdT3PYF.UZEcwQ=="; @@ -93,33 +93,32 @@ const getUserProfile = async (req, res) => { const scrapeLinkedInProfile = async (profileUrl) => { console.log("Scraping LinkedIn profile:", profileUrl); - const browser = await puppeteer.launch({ - headless: false, + + const browser = await chromium.launch({ + headless: true, // headless mode pour serveur args: ["--no-sandbox", "--disable-setuid-sandbox"], - }); // headless: true si tu veux sans UI - const page = await browser.newPage(); - - console.log("Using email:", email); - - // 1. Aller sur la page de login - await page.goto("https://www.linkedin.com/login", { - waitUntil: "networkidle2", }); + const page = await browser.newPage(); + + // 1. Login + await page.goto("https://www.linkedin.com/login", { + waitUntil: "networkidle", + }); console.log("Login page loaded"); - // 2. Connexion avec identifiants - await page.type("#username", email, { delay: 50 }); - await page.type("#password", password, { delay: 50 }); + await page.fill("#username", email); + await page.fill("#password", password); await Promise.all([ page.click('[type="submit"]'), - page.waitForNavigation({ waitUntil: "networkidle2" }), + page.waitForNavigation({ waitUntil: "networkidle" }), ]); + console.log("Logged in"); - // 3. Aller sur le profil - await page.goto(profileUrl, { waitUntil: "networkidle2" }); + // 2. Aller sur le profil + await page.goto(profileUrl, { waitUntil: "networkidle" }); - // 4. Extraire les infos + // 3. Extraire infos const profileData = await page.evaluate(() => { const getText = (selector) => document.querySelector(selector)?.innerText || null; @@ -129,14 +128,14 @@ const scrapeLinkedInProfile = async (profileUrl) => { ); return { - name: getText(".pv-text-details__left-panel h1"), + name: getText("h1"), headline: getText(".pv-text-details__left-panel .text-body-medium"), location: getText(".pv-text-details__left-panel .text-body-small"), about: getText(".pv-about-section") || - getText(".display-flex.ph5.pv3 .break-words"), - experiences: getAllText(".pv-entity__summary-info"), - education: getAllText(".pv-education-entity"), + getText(".pv-shared-text-with-see-more"), + experiences: getAllText("section#experience-section li"), + education: getAllText("section#education-section li"), skills: getAllText(".pv-skill-category-entity__name-text"), }; });