Beginner4 steps

How to Extract Email Addresses from a Website

Finding publicly listed contact email addresses across multiple pages of a website requires fetching each page and applying pattern matching. Doing this at scale means handling pagination, varying page structures, and consistent data delivery.

Step-by-Step Guide

1

Fetch the target page

Send the URL to the AlterLab API to retrieve the full HTML content, including any dynamically loaded contact sections.

2

Apply regex pattern matching

Use a standard email regex pattern to extract all email addresses from the returned HTML. Filter out common no-reply or placeholder addresses as needed.

3

Deduplicate and validate results

Remove duplicates and validate the format of extracted addresses before storing them.

4

Crawl additional pages

Repeat the process for contact, about, and team pages on the same domain to maximize coverage.

Code Example

import requests
import re

def extract_emails(url: str, api_key: str) -> list[str]:
    response = requests.post(
        "https://alterlab.io/api/v1/scrape",
        headers={"X-API-Key": api_key, "Content-Type": "application/json"},
        json={"url": url},
    )
    html = response.json().get("html", "")
    pattern = r'[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}'
    return list(set(re.findall(pattern, html)))

emails = extract_emails("https://example.com/contact", "YOUR_API_KEY")
print(emails)

Replace YOUR_API_KEY with your key from the dashboard. No credit card required.

Ready to try it?

Run this tutorial on live websites with AlterLab's API. Start free — no credit card required.

Frequently Asked Questions

Responsible Use

AlterLab is designed for extracting publicly available data. Always review the terms of service for any website you access, respect robots.txt directives, and ensure your use case complies with applicable laws in your jurisdiction.

More tutorials

Browse all how-to guides for web scraping — from beginner extractions to advanced multi-page pipelines.

Your first scrape.
Sixty seconds.

$1 free balance. No credit card. No SDK.Just a POST request.

terminal
curl -X POST https://api.alterlab.io/v1/scrape \
-H "X-API-Key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "formats": ["markdown"]}'

No credit card required · Up to 5,000 free scrapes · Balance never expire

    How to Extract Email Addresses from a Website | AlterLab | AlterLab