DEV Community

Алексей Спинов
Алексей Спинов

Posted on

How to Build an Email Finder That Actually Works (Node.js)

Email finders are one of the most valuable scraping tools. Here is how to build one that finds real emails.

Method 1: Scrape from Websites

const cheerio = require("cheerio");

async function findEmails(url) {
  const res = await fetch(url, { headers: { "User-Agent": "EmailBot/1.0" } });
  const html = await res.text();
  const $ = cheerio.load(html);
  $("script, style").remove();
  const text = $("body").text();

  const emails = [...new Set(
    (text.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g) || [])
    .filter(e => !e.includes("example.com") && !e.includes("noreply"))
  )];

  // Also check mailto links
  $("a[href^=mailto:]").each((i, el) => {
    const e = $(el).attr("href").replace("mailto:","").split("?")[0];
    if (!emails.includes(e)) emails.push(e);
  });

  return emails;
}
Enter fullscreen mode Exit fullscreen mode

Method 2: Pattern-Based Guessing

function guessEmails(name, domain) {
  const [first, last] = name.toLowerCase().split(" ");
  return [
    `${first}@${domain}`,
    `${first}.${last}@${domain}`,
    `${first[0]}${last}@${domain}`,
    `${first}${last[0]}@${domain}`,
    `${first}_${last}@${domain}`
  ];
}
// Then verify with SMTP check or API
Enter fullscreen mode Exit fullscreen mode

Method 3: Common Pages to Check

Most company emails are on:

  • /contact
  • /about
  • /team
  • /support
  • Footer of any page
const pages = ["/contact", "/about", "/team", "/support"];
const allEmails = [];
for (const page of pages) {
  const emails = await findEmails(domain + page);
  allEmails.push(...emails);
}
const unique = [...new Set(allEmails)];
Enter fullscreen mode Exit fullscreen mode

Resources


Need emails extracted from websites? $20. Any website, clean CSV output. Email: Spinov001@gmail.com | Hire me

Top comments (0)