Example input
const request = require('request-promise');
const cheerio = require('cheerio');
async function scrapeProfileName(url) {
// Make a request to the LinkedIn profile page
const html = await request(url);
// Load the HTML into cheerio
const $ = cheerio.load(html);
// Find the element containing the profile name
const nameElement = $('.pv-top-card-section__name');
// Extract the text from the element
const name = nameElement.text();
return name;
}
Example output
This code calls the scrapeProfileName function with the LinkedIn profile URL 'https://www.linkedin.com/in/john-doe/'. Once the function has finished scraping the profile and extracting the profile name, it will return a Promise object.
The then method is called on the Promise object, which takes a callback function as an argument. This callback function will be executed when the Promise is resolved, with the resolved value (in this case, the profile name) passed as its argument.
The callback function simply logs the profile name to the console using console.log.
So, when this code is executed, the profile name of the LinkedIn profile located at the URL 'https://www.linkedin.com/in/john-doe/' will be scraped and logged to the console.