Skip to content

Instantly share code, notes, and snippets.

@juanmanavarro
Last active October 23, 2023 09:08
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 juanmanavarro/19f87b71c751ba78743fbafa71802e63 to your computer and use it in GitHub Desktop.
Save juanmanavarro/19f87b71c751ba78743fbafa71802e63 to your computer and use it in GitHub Desktop.
Extract email addresses from a URL
const axios = require('axios');
async function findEmails(url) {
try {
const response = await axios.get(url);
const html = response.data;
const emailRegex = /[\w.-]+@[\w.-]+\.\w+/g;
let emails = html.match(emailRegex);
if (emails && emails.length) {
emails = [...new Set(emails)];
console.log('Fond emails:', emails);
} else {
console.log('Not found emails at this url.');
}
} catch (error) {
console.error('Error', error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment