Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

PythonNode.js

Email Scraper Examples (Python & Node.js)

HasData_bannner

This repository contains practical scripts to extract email addresses from web pages using Python and Node.js. It includes examples for both regex-based and API-based extraction, covering single sites, multiple URLs, and AI-enhanced scraping.

Table of Contents

  1. Requirements
  2. Project Structure
  3. Email Scraping Examples

Requirements

Python 3.10+ or Node.js 18+

Python Setup

Required packages:

  • requests

Install:

pip install requests

Node.js Setup

Required packages:

  • axios

Install:

npm install axios

Project Structure

email-scraping-examples/
│
├── python/
│ ├── regex_single_site.py
│ ├── regex_urls_from_file.py
│ ├── regex_urls_from_list.py
│ ├── api_email_scraper.py
│ ├── api_ai_email_scraper.py
│ ├── api_urls_from_file.py
│ ├── api_urls_from_list.py
│ ├── google_serp_scraper.py
│ ├── google_maps_scraper.py
│
├── nodejs/
│ ├── regex_single_site.js
│ ├── regex_urls_from_file.js
│ ├── regex_urls_from_list.js
│ ├── api_email_scraper.js
│ ├── api_ai_email_scraper.js
│ ├── api_urls_from_file.js
│ ├── api_urls_from_list.js
│ ├── google_serp_scraper.js
│ ├── google_maps_scraper.js
│
└── README.md

Each script focuses on a specific method of email extraction. No frameworks. Just clean and minimal examples to get things done.

Email Scraping Examples

Full article with email scraping examples you can find at hasdata.com.

Regex Email Scraping

Extract emails using regular expressions from a given URL or multiple URLs (from a file or list).

ParameterDescriptionExample
target_urlURL to scrape emails from'https://example.com'
file_pathFile with URLs (for batch)'urls.txt'
output_fileFile to save found emails'emails.txt'

API Email Scraping (HasData)

Use HasData's web scraping API to extract emails, phone numbers, addresses, and company names from websites.

ParameterDescriptionExample
api_keyHasData API key'your-api-key'
target_urlWebsite URL to scrape'https://example.com'

AI Email Extraction (HasData)

Use HasData’s AI extraction feature to extract emails and additional details from complex websites.

ParameterDescriptionExample
api_keyAPI key for HasData service'YOUR-API-KEY'
urls.txtFile containing list of URLs to scrape'urls.txt'
proxyTypeType of proxy to use for requests'datacenter'
proxyCountryProxy country code to route requests through'US'
jsRenderingEnable JavaScript rendering on pagesTrue
aiExtractRulesAI extraction rules for address, phone, email, companySee script for JSON structure
results_ai.jsonOutput JSON file with scraped data'results_ai.json'
results_ai.csvOutput CSV file with scraped data'results_ai.csv'

Google SERP Email Extraction

Search Google for specific queries and extract emails from the resulting URLs.

ParameterDescriptionExample
api_keyYour HasData API key"YOUR-API-KEY"
keywordsList of search queries for Google SERP["restaurant in New York", "coffee shop in Los Angeles"]
countryCountry code for localized search"US"
languageLanguage code for search results"en"
num_resNumber of organic results per query10
urlsList of URLs collected from SERP["https://example.com", "https://another.com"]
resultsList of dictionaries with URL and extracted emails[{"url": "https://example.com", "emails": ["info@example.com"]}]

Google Maps Email Extraction

Extract emails and contact details from Google Maps listings for a given keyword and location.

ParameterDescriptionExample
api_keyAPI key for HasData API'YOUR-API-KEY'
keywordsList of keywords to search in Google Maps["coffee shops NYC", "book stores Boston"]
languageLanguage code for Google Maps search'en'
results.jsonOutput JSON file with combined results'results.json'
results.csvOutput CSV file with combined results'results.csv'

Disclaimer

These examples are for educational purposes only. Learn more about the legality of web scraping.

About

This repository provides a collection of practical, easy-to-understand examples for scraping emails from websites using both Python and Node.js. Whether you want to extract emails via simple regex, leverage powerful APIs like HasData, or even tap into AI-driven data extraction, this repo has got you covered.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages