Python scripts that automate digital marketing and lead generation tasks, including email scraping, email generation, customer list building, and forum data extraction.
git clone https://github.com/yesblogger/python_automation.gitpython_automation is a collection of Python scripts designed to automate repetitive digital marketing and lead generation workflows. The repository includes modules for scraping emails using both the Requests library and Selenium, generating outreach emails, building customer lists, and extracting data from forums. These tools are built for marketers and growth professionals who need to streamline prospecting and data collection tasks. All scripts are written in Python and licensed under MIT.
1. **Install dependencies**: Run `pip install requests beautifulsoup4 pandas` to install required libraries. 2. **Customize the script**: Replace [TASK], [LIBRARIES], [SPECIFIC REQUIREMENTS], [EDGE CASES], [LOG_FILE], [OUTPUT_FILE], and [COMMON_ERRORS] in the prompt template with your specific needs. 3. **Run the script**: Execute with `python script_name.py` or use an IDE like VS Code or PyCharm. 4. **Review logs**: Check the log file (default: email_scraper.log) for debugging information and progress tracking. 5. **Process results**: Use the output file (default: forum_emails.csv) for your marketing campaigns or further processing. **Tips for better results:** - For forum scraping, always check the site's robots.txt and terms of service first - Adjust MAX_PAGES based on forum size and your rate limits - Add delays between requests (e.g., `time.sleep(2)`) to avoid being blocked - For email generation, consider using libraries like `faker` to create realistic test emails - For customer list building, combine this with LinkedIn scraping or CRM exports
Scrape email addresses from websites using Requests or Selenium
Automatically generate outreach or marketing emails
Build and maintain customer or prospect lists
Extract user data and leads from online forums
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/yesblogger/python_automationCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Write a Python script to [TASK] using [LIBRARIES]. The script should [SPECIFIC REQUIREMENTS], such as handling [EDGE CASES], logging progress to [LOG_FILE], and saving results to [OUTPUT_FILE]. Include error handling for [COMMON_ERRORS].
```python
import requests
from bs4 import BeautifulSoup
import pandas as pd
import logging
from datetime import datetime
# Configure logging
logging.basicConfig(filename='email_scraper.log', level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
# Constants
TARGET_URL = "https://example-forum.com/threads/lead-generation"
OUTPUT_FILE = "forum_emails.csv"
MAX_PAGES = 5
# User-Agent to mimic browser
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}
# Email regex pattern
import re
EMAIL_REGEX = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
def scrape_forum_emails(url, max_pages=5):
"""Scrape emails from forum threads and return as DataFrame"""
emails = []
for page in range(1, max_pages + 1):
try:
response = requests.get(f"{url}?page={page}", headers=HEADERS, timeout=10)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
threads = soup.find_all('div', class_='thread')
for thread in threads:
thread_title = thread.find('h3').text.strip()
content = thread.find('div', class_='message').text
# Find all emails in thread content
found_emails = re.findall(EMAIL_REGEX, content)
emails.extend(found_emails)
logging.info(f"Page {page}: Found {len(found_emails)} emails in '{thread_title}'")
except requests.RequestException as e:
logging.error(f"Error scraping page {page}: {str(e)}")
continue
return pd.DataFrame({'email': list(set(emails))})
if __name__ == "__main__":
logging.info("Starting forum email scraping...")
try:
df_emails = scrape_forum_emails(TARGET_URL, MAX_PAGES)
if not df_emails.empty:
df_emails.to_csv(OUTPUT_FILE, index=False)
logging.info(f"Successfully saved {len(df_emails)} unique emails to {OUTPUT_FILE}")
print(f"Scraping complete! Found {len(df_emails)} unique emails.")
else:
logging.warning("No emails found in the specified pages.")
print("No emails found. Check the target URL or adjust scraping parameters.")
except Exception as e:
logging.error(f"Script failed: {str(e)}")
print(f"Error occurred: {str(e)}")
```
**Output Explanation:**
This script scrapes email addresses from forum threads by:
1. Iterating through 5 pages of a target forum
2. Extracting email patterns from thread content using regex
3. Deduplicating results and saving to a CSV file
4. Logging all actions and errors for debugging
The script handles common issues like:
- Rate limiting by using a browser-like User-Agent
- Network timeouts with a 10-second limit
- Malformed HTML with BeautifulSoup's robust parser
- Duplicate emails by converting to a set before saving
When run, it would typically output something like:
```
Starting forum email scraping...
Page 1: Found 12 emails in 'Best CRM Tools for 2024'
Page 2: Found 8 emails in 'Email Marketing Strategies'
Page 3: Found 5 emails in 'Lead Generation Hacks'
Page 4: Found 0 emails in 'Off-topic discussions'
Page 5: Found 3 emails in 'B2B Sales Techniques'
Successfully saved 28 unique emails to forum_emails.csv
Scraping complete! Found 28 unique emails.
```Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan