A Python web scraper for extracting daily horoscopes from Astrology.
- Scrapes daily horoscopes for all 12 zodiac signs
- Extracts horoscope text, date, and ratings (Creativity, Love, Business)
- Saves data to JSON or CSV format
- Respectful scraping with configurable delays between requests
- Error handling and retry logic
- Clean, well-documented code
- Install Python 3.7 or higher
- Install dependencies:
pip install -r requirements.txtOr install manually:
pip install requests beautifulsoup4 lxmlRun the scraper to get all horoscopes:
python horoscope_scraper.pyThis will:
- Scrape horoscopes for all 12 zodiac signs
- Save results to
horoscopes.jsonandhoroscopes.csv - Print a summary to the console
from horoscope_scraper import HoroscopeScraper
# Create scraper instance
scraper = HoroscopeScraper(delay=1.0)
# Scrape a single sign
aries = scraper.scrape_sign('aries')
print(aries)
# Scrape all signs
all_horoscopes = scraper.scrape_all()
# Save to JSON
scraper.save_to_json(all_horoscopes, 'my_horoscopes.json')
# Save to CSV
scraper.save_to_csv(all_horoscopes, 'my_horoscopes.csv')- aries
- taurus
- gemini
- cancer
- leo
- virgo
- libra
- scorpio
- sagittarius
- capricorn
- aquarius
- pisces
[
{
"sign": "Aries",
"date": "January 30, 2026",
"horoscope": "The Moon spends another day in your home and family sector...",
"ratings": {
"creativity": "Excellent",
"love": "Excellent",
"business": "Fair"
},
"scraped_at": "2026-01-30T12:00:00.000000"
}
]| sign | date | horoscope | creativity | love | business | scraped_at |
|---|---|---|---|---|---|---|
| Aries | January 30, 2026 | The Moon spends... | Excellent | Excellent | Fair | 2026-01-30T12:00:00 |
To be respectful to the server, the scraper includes a delay between requests:
# Default: 1 second delay
scraper = HoroscopeScraper(delay=1.0)
# Faster (use with caution)
scraper = HoroscopeScraper(delay=0.5)
# Slower (more respectful)
scraper = HoroscopeScraper(delay=2.0)- Be Respectful : Don't scrape too frequently. The default 1-second delay is reasonable.
- Cache Results : Save the results and reuse them instead of scraping repeatedly.
- Error Handling : The scraper handles errors gracefully, but check your internet connection if you encounter issues.
- Terms of Service : Make sure your use complies with Cafe Astrology's terms of service.
Cafe Astrology Horoscope Scraper
==================================================
Example 1: Scraping single sign (Aries)
Scraping Aries...
Sign: Aries
Date: January 30, 2026
Horoscope: The Moon spends another day in your home and family sector, dear Aries...
Ratings: {'creativity': 'Excellent', 'love': 'Excellent', 'business': 'Fair'}
==================================================
Example 2: Scraping all signs
==================================================
Scraping Aries...
Scraping Taurus...
Scraping Gemini...
...
Saved 12 horoscopes to horoscopes.json
Saved 12 horoscopes to horoscopes.csv
Successfully scraped 12 horoscopes
Summary:
Aries: 1234 characters
Taurus: 1156 characters
...
Make sure all dependencies are installed:
pip install -r requirements.txt- Check your internet connection
- The website might be temporarily unavailable
- Try increasing the delay between requests
- The website structure may have changed
- Check the error messages for details
- The scraper includes fallback methods to find content
scraper = HoroscopeScraper()
horoscopes = scraper.scrape_all()
# Filter by sign
aries_horoscopes = [h for h in horoscopes if h['sign'] == 'Aries']
# Get signs with excellent love ratings
love_excellent = [
h for h in horoscopes
if h.get('ratings', {}).get('love') == 'Excellent'
]
# Create custom output
for h in horoscopes:
print(f"{h['sign']}: {h['horoscope'][:100]}...")# π³ Docker Setup for Horoscope & Numerology App
Complete Docker containerization for your React + Vite frontend with Python horoscope scraper backend.
## π― What's Included
- **Frontend Container**: React + Vite app with Nginx
- **Backend Container**: Python Flask API with horoscope scraper
- **Development Mode**: Hot reload for both frontend and backend
- **Production Mode**: Optimized builds with Nginx reverse proxy
- **CI/CD Pipeline**: GitHub Actions workflow
- **Management Scripts**: Easy Docker management
## π¦ Quick Start
### Prerequisites
- Docker 20.10+ and Docker Compose 2.0+
- Git
### 1. Clone and Setup
```bash
# Clone your repository
git clone <your-repo-url>
cd <your-repo>
# Create environment file
cp .env.example .env
# Edit .env with your settings (optional)
nano .env# Using docker-compose
docker-compose -f docker-compose.dev.yml up
# OR using the management script
chmod +x docker-manager.sh
./docker-manager.sh start-devAccess:
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
# Using docker-compose
docker-compose up -d --build
# OR using the management script
./docker-manager.sh start-prodAccess:
- Frontend: http://localhost
- Backend API: http://localhost:5000
your-project/
βββ frontend/ # React application
β βββ src/
β β βββ componets/
β β β βββ Navbar/
β β β βββ Home/
β β β βββ Learn/
β β β βββ NumCalculator/
β β β βββ GetSign/
β β β βββ Footer/
β β β βββ LifePath/
β β βββ App.jsx
β βββ public/
β βββ package.json
β βββ vite.config.js
β βββ index.html
β
βββ Dockerfile.frontend # Frontend image definition
βββ Dockerfile.backend # Backend image definition
βββ docker-compose.yml # Production orchestration
βββ docker-compose.dev.yml # Development orchestration
βββ nginx.conf # Nginx configuration
βββ .dockerignore # Files to exclude from images
β
βββ horoscope_scraper.py # Horoscope scraper
βββ api.py # Flask REST API
βββ requirements-backend.txt # Python dependencies
β
βββ docker-manager.sh # Management script
βββ .env.example # Environment template
βββ DOCKER_GUIDE.md # Detailed documentation
βββ README.md # This file
The docker-manager.sh script simplifies Docker operations:
# Make executable (first time only)
chmod +x docker-manager.sh
# Start production
./docker-manager.sh start-prod
# Start development
./docker-manager.sh start-dev
# Stop all services
./docker-manager.sh stop
# View logs
./docker-manager.sh logs
./docker-manager.sh logs backend
./docker-manager.sh logs frontend
# Check status
./docker-manager.sh status
# Access container shell
./docker-manager.sh shell frontend
./docker-manager.sh shell backend
# Rebuild images
./docker-manager.sh build
# Clean everything
./docker-manager.sh clean
# See all commands
./docker-manager.sh helpEdit .env file to configure:
# Backend
FLASK_ENV=production
CACHE_DURATION_HOURS=6
SCRAPER_DELAY=1.0
# Frontend
VITE_API_URL=http://localhost:5000
VITE_APP_NAME="Astrology App"Edit docker-compose.yml:
services:
frontend:
ports:
- "8080:80" # Change from 80 to 8080
backend:
ports:
- "3001:5000" # Change from 5000 to 3001The backend provides the following endpoints:
GET / - API info
GET /api/signs - List all zodiac signs
GET /api/horoscope/<sign> - Get horoscope for a sign
GET /api/horoscopes - Get all horoscopes
GET /api/horoscopes/filter - Filter by rating
POST /api/clear-cache - Clear the cache
# Get all signs
curl http://localhost:5000/api/signs
# Get Aries horoscope
curl http://localhost:5000/api/horoscope/aries
# Get all horoscopes
curl http://localhost:5000/api/horoscopes
# Filter by love rating
curl "http://localhost:5000/api/horoscopes/filter?rating_type=love&rating_value=Excellent"# Find what's using the port
lsof -i :80
lsof -i :5000
# Stop the process or change port in docker-compose.ymlIn Development:
// frontend/vite.config.js
proxy: {
'/api': {
target: 'http://localhost:5000', // Use localhost
changeOrigin: true
}
}In Production: The nginx.conf already handles this with reverse proxy.
# Development mode should auto-reload, but if not:
docker-compose -f docker-compose.dev.yml down
docker-compose -f docker-compose.dev.yml up --build
# For production:
docker-compose down
docker-compose up -d --build# Check logs
docker-compose logs backend
docker-compose logs frontend
# Check specific container
docker logs <container-id># Rebuild without cache
docker-compose build --no-cache
docker-compose up -ddocker-compose psdocker stats# All logs
docker-compose logs -f
# Specific service
docker-compose logs -f backend
docker-compose logs -f frontend
# Last 100 lines
docker-compose logs --tail=100 backend- Make changes to your code
- See changes instantly (hot reload is enabled)
- Test in the browser
- Commit when satisfied
Changes to Python files automatically reload the Flask server.
Changes to React components automatically rebuild and reload in browser.
# SSH into your server
ssh user@your-server.com
# Clone repository
git clone <your-repo>
cd <your-repo>
# Copy and configure environment
cp .env.example .env
nano .env
# Start production
docker-compose up -d --build
# Check status
docker-compose psThe included .github/workflows/docker-ci.yml automates:
- Building Docker images
- Running tests
- Pushing to container registry
- Deploying to production
Setup:
-
Add secrets to GitHub repository:
DEPLOY_KEY: SSH key for serverDEPLOY_HOST: Server IP/domainDEPLOY_USER: SSH username
-
Push to main branch:
git push origin main
-
GitHub Actions will automatically deploy!
-
Don't commit
.envfile# Add to .gitignore echo ".env" >> .gitignore
-
Use secrets for sensitive data
- Store API keys in
.env - Use Docker secrets in production
- Store API keys in
-
Update dependencies regularly
# Frontend cd frontend && npm update # Backend pip install --upgrade -r requirements-backend.txt
-
Don't expose backend port in production
# Comment out in docker-compose.yml # backend: # ports: # - "5000:5000"
- Docker Guide - Comprehensive documentation
- Horoscope Scraper README - Scraper documentation
- Quick Start - Quick reference
- Check the logs:
./docker-manager.sh logs - Review DOCKER_GUIDE.md
- Search issues in repository
- Create new issue with logs and error messages
[Your License Here]
- Fork the repository
- Create feature branch
- Make changes
- Test with Docker
- Submit pull request
Happy Coding! π
Made with β€οΈ using Docker π³import pandas as pd
scraper = HoroscopeScraper() horoscopes = scraper.scrape_all() df = pd.DataFrame(horoscopes)
print(df['ratings'].value_counts())
df.to_excel('horoscopes.xlsx', index=False)
This scraper is provided for educational purposes. Please respect Cafe Astrology's terms of service and copyright when using this tool.
This tool is not affiliated with Cafe Astrology. Please use responsibly and in accordance with the website's terms of service. Don't abuse the scraper by making excessive requests.