Skip to content

Instantly share code, notes, and snippets.

@Deamoner
Created January 5, 2023 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deamoner/bb2fb62248d955b11c1c64113a4b9090 to your computer and use it in GitHub Desktop.
Save Deamoner/bb2fb62248d955b11c1c64113a4b9090 to your computer and use it in GitHub Desktop.
nodejs function to get all the social meta data of a url
const request = require('request');
const cheerio = require('cheerio');
function getSocialMetaData(url) {
request(url, (error, response, html) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);
const title = $('title').text();
const description = $('meta[name="description"]').attr('content');
const image = $('meta[property="og:image"]').attr('content');
console.log(`Title: ${title}`);
console.log(`Description: ${description}`);
console.log(`Image: ${image}`);
} else {
console.log(`Error retrieving data: ${error}`);
}
});
}
getSocialMetaData('https://www.example.com');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment