This commit is contained in:
AMAICDAX 2025-09-09 16:21:15 +02:00
parent cf36a8dd63
commit 9d6d51451b

View file

@ -2,7 +2,7 @@
const axios = require("axios"); const axios = require("axios");
const querystring = require("querystring"); const querystring = require("querystring");
const puppeteer = require("puppeteer"); const { chromium } = require("playwright");
const clientId = "780w7gsy8eysmj"; const clientId = "780w7gsy8eysmj";
const clientSecret = "WPL_AP1.w6OTTkAndAdT3PYF.UZEcwQ=="; const clientSecret = "WPL_AP1.w6OTTkAndAdT3PYF.UZEcwQ==";
@ -93,33 +93,32 @@ const getUserProfile = async (req, res) => {
const scrapeLinkedInProfile = async (profileUrl) => { const scrapeLinkedInProfile = async (profileUrl) => {
console.log("Scraping LinkedIn profile:", 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"], 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"); console.log("Login page loaded");
// 2. Connexion avec identifiants await page.fill("#username", email);
await page.type("#username", email, { delay: 50 }); await page.fill("#password", password);
await page.type("#password", password, { delay: 50 });
await Promise.all([ await Promise.all([
page.click('[type="submit"]'), page.click('[type="submit"]'),
page.waitForNavigation({ waitUntil: "networkidle2" }), page.waitForNavigation({ waitUntil: "networkidle" }),
]); ]);
console.log("Logged in");
// 3. Aller sur le profil // 2. Aller sur le profil
await page.goto(profileUrl, { waitUntil: "networkidle2" }); await page.goto(profileUrl, { waitUntil: "networkidle" });
// 4. Extraire les infos // 3. Extraire infos
const profileData = await page.evaluate(() => { const profileData = await page.evaluate(() => {
const getText = (selector) => const getText = (selector) =>
document.querySelector(selector)?.innerText || null; document.querySelector(selector)?.innerText || null;
@ -129,14 +128,14 @@ const scrapeLinkedInProfile = async (profileUrl) => {
); );
return { return {
name: getText(".pv-text-details__left-panel h1"), name: getText("h1"),
headline: getText(".pv-text-details__left-panel .text-body-medium"), headline: getText(".pv-text-details__left-panel .text-body-medium"),
location: getText(".pv-text-details__left-panel .text-body-small"), location: getText(".pv-text-details__left-panel .text-body-small"),
about: about:
getText(".pv-about-section") || getText(".pv-about-section") ||
getText(".display-flex.ph5.pv3 .break-words"), getText(".pv-shared-text-with-see-more"),
experiences: getAllText(".pv-entity__summary-info"), experiences: getAllText("section#experience-section li"),
education: getAllText(".pv-education-entity"), education: getAllText("section#education-section li"),
skills: getAllText(".pv-skill-category-entity__name-text"), skills: getAllText(".pv-skill-category-entity__name-text"),
}; };
}); });