Complete setup guide from scratch, including initial database population and ethical scraping practices.
Note: This project works without Celery. Celery is optional and recommended for production, but the system automatically falls back to threading if Celery is not available.
- Prerequisites
- Initial Setup
- Initial Data Population
- Automated Daily Scraping
- Best Practices
- Troubleshooting
- Next Steps
- Additional Resources
- Python 3.11+
- PostgreSQL 15+ (or SQLite for development)
- Redis 6+ (optional, for caching and Celery if you choose to use it)
- Git
# Clone the repository
git clone <repository-url>
cd FKApi
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Copy example environment file
cp .env.example .env
# Edit .env with your settings
# Minimum required:
# - Database credentials (POSTGRES_*)
# - Django secret key (DJANGO_SECRET_KEY)
# - Scraper user agent (SCRAPER_USER_AGENT)# Create database (PostgreSQL)
createdb fkapi
# Or use Docker
docker run -d --name postgres \
-e POSTGRES_DB=fkapi \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=yourpassword \
-p 5432:5432 \
postgres:15
# Run migrations
cd fkapi
python manage.py migrate
# Create superuser
python manage.py createsuperuser# Start development server
python manage.py runserver
# In another terminal, test API
curl http://localhost:8000/api/health
# Access admin interface
# http://localhost:8000/adminIMPORTANT: The database starts empty. You need to populate it with data through ethical scraping.
Always check the website's robots.txt before scraping:
curl https://www.footballkitarchive.com/robots.txtWhat to look for:
Disallowrules (pages you cannot scrape)Crawl-delay(minimum time between requests)User-agentrules (specific rules for your bot)
Rules to follow:
- ✅ Respect all
Disallowrules - ✅ Honor
Crawl-delayif specified (minimum 2 seconds recommended) - ✅ Use a proper User-Agent header
- ✅ Include contact information in User-Agent
Visit the website's Terms of Service page and check:
- Is scraping explicitly allowed?
- Are there rate limits mentioned?
- What is the allowed usage?
- Are there attribution requirements?
Edit your .env file:
# Scraper identification (REQUIRED)
SCRAPER_USER_AGENT="FootballKitArchiveBot/1.0 (contact@youremail.com)"
# Rate limiting (REQUIRED)
HTTP_TIMEOUT=15
HTTP_MAX_RETRIES=3
HTTP_BACKOFF_FACTOR=0.5
# Delays between requests (REQUIRED - minimum 2 seconds)
DELAY_MIN=2
DELAY_MAX=5Always test with a single request first:
# Test scraping a single kit
python manage.py scrape_kit_by_slug --slug "arsenal-2024-home-kit"
# Verify:
# - Request was successful
# - Data was saved correctly
# - No errors in logs
# - Respectful delay was usedScrape one club at a time to distribute load:
# Scrape all kits for a specific club
python manage.py scrape_whole_club --club-slug "arsenal-kits"
# This will:
# - Get list of all kits for the club
# - Scrape each kit with delays (2-5 seconds)
# - Save to database
# - Continue even if some failRecommended Schedule for Initial Population:
- Week 1: Top 50 clubs (5-10 clubs per day)
- Week 2-4: Next 100 clubs (10-15 clubs per week)
- Week 5-8: Remaining clubs (20-30 clubs per week)
Total Time: 8 weeks to scrape ~5,000 clubs (300,000+ kits)
After initial population, use this for daily updates:
# Scrape latest updated kits (first 5 pages)
python manage.py scrape_latest --start-page 1 --end-page 5
# This scrapes:
# - Only the "Latest Kits" pages
# - Most recently updated/added kits
# - With proper delays between requests
# - Stops when all kits on a page already existOnce your database is populated, you can set up automated daily scraping. The project supports multiple options:
Celery provides better performance and monitoring. See celery-setup.md for detailed instructions.
Note: Celery is optional. The system works without it using threading fallback.
# Edit crontab
crontab -e
# Add daily scraping at 3 AM
0 3 * * * cd /path/to/FKApi && source venv/bin/activate && cd fkapi && python manage.py scrape_latest --start-page 1 --end-page 5- Open Task Scheduler
- Create Basic Task
- Set trigger: Daily at 3:00 AM
- Set action: Run program
- Program:
C:\path\to\venv\Scripts\python.exe - Arguments:
fkapi\manage.py scrape_latest --start-page 1 --end-page 5 - Start in:
C:\path\to\FKApi\fkapi
- Program:
Always use delays between requests:
- Minimum: 2 seconds between requests
- Recommended: 2-5 seconds (randomized)
- Maximum: Respect
Crawl-delayfrom robots.txt
The scraper already includes delays, but verify:
# In scrapers.py, delays are configured:
DELAY_MIN = 2 # seconds
DELAY_MAX = 5 # secondsThe scraper handles errors gracefully:
- Retries failed requests (with exponential backoff)
- Logs all errors for review
- Continues processing even if some items fail
- Respects HTTP status codes (429, 503, etc.)
Monitor your scraping activity:
# View scraper logs
tail -f logs/scraper.log
# Check for errors
grep ERROR logs/scraper.log
# Monitor database growth
python manage.py shell
>>> from core.models import Kit
>>> Kit.objects.count()Regularly check data quality:
# Find kits with missing data
python manage.py shell
>>> from core.models import Kit
>>> Kit.objects.filter(main_img_url__isnull=True).count()
# Find duplicate kits
python manage.py find_duplicate_kits
# Check for broken images
python manage.py check_broken_imagesSolution: This is normal! The database starts empty. You need to populate it through scraping:
- Follow the "Initial Data Population" section above
- Start with a single club:
python manage.py scrape_whole_club --club-slug "arsenal-kits" - Gradually expand to more clubs
Solution: You're scraping too fast:
- Increase delays in
.env:DELAY_MIN=5 DELAY_MAX=10 - Reduce concurrent requests
- Add longer delays between club scrapes
Solution:
- Verify delays are not too high
- Check network connection
- Consider using proxy (if allowed by robots.txt)
- Scrape during off-peak hours
Solution:
- Verify PostgreSQL is running:
pg_isready - Check database credentials in
.env - Verify database exists:
psql -l | grep fkapi - Test connection:
python manage.py dbshell
- ✅ Complete initial setup
- ✅ Review robots.txt and Terms of Service
- ✅ Configure scraper settings
- ✅ Test with single kit scrape
- ✅ Begin gradual club scraping
- ✅ Set up automated daily scraping
- ✅ Monitor and maintain data quality
- Scraping Guide - Complete ethical scraping guide with robots.txt, rate limiting, workflows
- Quick Scraping - Quick reference for common scraping tasks
- Celery Setup - Optional: Celery configuration (recommended for production)
- Deployment Guide - Production deployment instructions
- ✅ Check robots.txt before scraping
- ✅ Review Terms of Service
- ✅ Use proper User-Agent with contact info
- ✅ Respect rate limits (minimum 2 seconds between requests)
- ✅ Only scrape what you need
- ✅ Don't overload servers
- ✅ Handle errors gracefully
- ✅ Monitor your scraping activity
- ✅ Give attribution when displaying data
Remember: Web scraping may be subject to legal restrictions. Always ensure you have permission to scrape the target website.
Last Updated: 2026-01-17 Maintained by: sunr4y