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

Python
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 . No credit card required.

Try this yourself with AlterLab

Run this tutorial on live websites with AlterLab's API. Free tier includes 5,000 requests — no credit card required.

View API docs

Frequently Asked Questions

Can I extract emails that are only visible after JavaScript loads?

Yes — enable `render_js: true` in your request to execute JavaScript before extraction. This reveals emails loaded via contact forms or dynamic content blocks.

Is extracting publicly listed emails legal?

Extracting publicly listed contact information may vary in legality by jurisdiction. Always review the target website's terms of service and comply with applicable data protection regulations such as GDPR in your jurisdiction.

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 credit — up to 5,000 scrapes. No credit card.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 · $1 free credit, up to 5,000 scrapes · Balance never expires