Last active
October 23, 2023 09:08
-
-
Save juanmanavarro/19f87b71c751ba78743fbafa71802e63 to your computer and use it in GitHub Desktop.
Extract email addresses from a URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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