A Node.js project to scrape phone numbers from WhatsApp groups and Telegram channels using multiple automation approaches.
- This tool is for educational purposes only
- Scraping WhatsApp data may violate WhatsApp's Terms of Service
- Use responsibly and only with groups you have permission to access
- Respect privacy and data protection laws in your jurisdiction
- Multiple Platforms: Support for WhatsApp groups and Telegram channels
- Multiple Scraping Approaches: Choose from 4 different methods
- Multiple Output Formats: JSON, CSV, and TXT files
- Phone Number Validation: Automatically validates and formats phone numbers
- Deduplication: Removes duplicate phone numbers
- Easy Configuration: Simple
.envfile setup
- Node.js (v16 or higher)
- npm or yarn
- WhatsApp account (for WhatsApp scraping)
- Telegram account (for Telegram scraping)
- Telegram API credentials (for Telegram scraping - see setup below)
- Access to the group/channel you want to scrape
- Clone or navigate to the project directory:
cd scrappers- Install dependencies:
npm install- Create a
.envfile from the example:
cp .env.example .env- Edit the
.envfile with your configuration:
For WhatsApp:
GROUP_NAME=Your Group Name Here
OUTPUT_FILE=output/phone-numbers.json
SCRAPER_APPROACH=whatsapp-webFor Telegram:
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
TELEGRAM_CHANNEL_USERNAME=channel_username
OUTPUT_FILE=output/phone-numbers.json
SCRAPER_APPROACH=telegramGetting Telegram API Credentials:
- Go to https://my.telegram.org/apps
- Log in with your phone number
- Create a new application
- Copy the
api_idandapi_hashto your.envfile
This is the most reliable approach using the whatsapp-web.js library.
npm run scraper:whatsapp-webSteps:
- Run the command
- Scan the QR code displayed in the terminal with your WhatsApp mobile app
- Wait for the scraper to extract phone numbers
- Results will be saved in the output directory
Direct browser automation using Puppeteer.
npm run scraper:puppeteerSteps:
- Run the command (browser window will open)
- Scan the QR code in the browser
- The scraper will automatically navigate to your group
- Results will be saved in the output directory
Similar to Puppeteer but using Playwright.
npm run scraper:playwrightSteps:
- Run the command (browser window will open)
- Scan the QR code in the browser
- The scraper will automatically navigate to your group
- Results will be saved in the output directory
Scrape phone numbers from Telegram channels using the Telegram Client API.
npm run scraper:telegramPrerequisites:
- Get your Telegram API credentials from https://my.telegram.org/apps
- Add
TELEGRAM_API_IDandTELEGRAM_API_HASHto your.envfile - Set
TELEGRAM_CHANNEL_USERNAMEto the channel username (without @)
Steps:
- Configure your
.envfile with Telegram credentials - Run the command
- Enter your phone number when prompted
- Enter the verification code sent to your Telegram
- The scraper will extract phone numbers from channel members
- Results will be saved in the output directory
Note: You need to be an admin of the channel or the channel must allow member visibility.
You can also use the main entry point which reads the SCRAPER_APPROACH from .env:
npm startThe scraper generates three output files in the output/ directory:
phone-numbers.json: Structured JSON with metadataphone-numbers.csv: CSV format for spreadsheet applicationsphone-numbers.txt: Simple text file with one number per line
{
"timestamp": "2024-01-15T10:30:00.000Z",
"total": 25,
"phoneNumbers": [
{
"number": "1234567890",
"name": "John Doe",
"formatted": "+1234567890"
}
]
}WhatsApp Variables:
| Variable | Description | Default |
|---|---|---|
GROUP_NAME |
Exact name of the WhatsApp group | Required |
OUTPUT_FILE |
Output file path (without extension) | output/phone-numbers.json |
SCRAPER_APPROACH |
Scraper method: whatsapp-web, puppeteer, playwright, or telegram |
whatsapp-web |
Telegram Variables:
| Variable | Description | Default |
|---|---|---|
TELEGRAM_API_ID |
Your Telegram API ID from https://my.telegram.org/apps | Required |
TELEGRAM_API_HASH |
Your Telegram API Hash from https://my.telegram.org/apps | Required |
TELEGRAM_CHANNEL_USERNAME |
Channel username (without @) | Required |
TELEGRAM_SESSION_FILE |
Session file path | sessions/telegram.session |
OUTPUT_FILE |
Output file path (without extension) | output/phone-numbers.json |
SCRAPER_APPROACH |
Set to telegram |
telegram |
scrappers/
βββ src/
β βββ scrapers/
β β βββ whatsapp-web-scraper.js # Recommended WhatsApp approach
β β βββ puppeteer-scraper.js # Puppeteer WhatsApp approach
β β βββ playwright-scraper.js # Playwright WhatsApp approach
β β βββ telegram-scraper.js # Telegram channel scraper
β βββ utils/
β βββ fileHandler.js # File operations
β βββ phoneUtils.js # Phone number utilities
βββ output/ # Generated output files
βββ sessions/ # Session data (WhatsApp & Telegram)
βββ .env # Configuration file
βββ .env.example # Example configuration
βββ package.json
βββ README.md
- Uses the official WhatsApp Web protocol
- Most stable and reliable
- Handles authentication automatically
- Stores session for future use
- Best for: Production use, reliability
- Direct browser automation
- More control over browser behavior
- Requires manual QR code scanning
- Best for: Custom automation needs
- Similar to Puppeteer
- Cross-browser support
- Modern API
- Best for: Testing different browsers
- Uses Telegram Client API (MTProto)
- Direct access to channel members
- Session-based authentication
- Best for: Telegram channel scraping
- Make sure WhatsApp Web is not connected on another device
- Close other WhatsApp Web sessions
- Try running the scraper again
- Verify the group name matches exactly (case-sensitive)
- Check that you have access to the group
- List available groups in the error message
- Delete the
sessions/folder and try again - Make sure your phone has internet connection
- Check if WhatsApp Web is blocked on your network
- Ensure you have permission to view group participants
- Some groups may restrict participant visibility
- Try a different scraper approach
- Verify your API credentials are correct
- Make sure you're using the correct phone number format (with country code)
- Check that the verification code is entered correctly
- Delete
sessions/telegram.sessionand try again
- You need to be an admin of the channel to view members
- Some channels have privacy settings that hide member phone numbers
- Verify the channel username is correct (without @)
- Session data is stored locally in the
sessions/directory - Never commit
.envfiles or session data to version control - Phone numbers are stored locally only
- Be mindful of data protection regulations (GDPR, etc.)
- The first run will require QR code scanning
- Subsequent runs with
whatsapp-web.jsmay reuse the session - Phone numbers are normalized to international format
- Duplicate numbers are automatically removed
Feel free to submit issues or pull requests for improvements.
MIT License - Use responsibly and ethically.
- whatsapp-web.js - WhatsApp Web API
- Puppeteer - Browser automation
- Playwright - Browser automation
- GramJS (telegram) - Telegram Client API