A comprehensive Python toolkit for downloading, processing, and searching government document collections. Originally designed for the Robert F. Kennedy Assassination Archives, but flexible enough for any document repository.
- Intelligently crawls websites to find and download all PDF files
- Configurable crawl depth and request delays to be respectful to servers
- Pre-configured for common U.S. government document collections
- Easy to add new website configurations through
config.py - Progress bars and detailed logging
- Automatically skips already downloaded files
- Convert scanned PDFs to searchable text using Tesseract OCR
- Memory-efficient processing that prevents system crashes
- Multi-threaded OCR for faster processing
- Resume capability for interrupted OCR jobs
- Web-based search interface to find documents
- Full-text search with highlighted results
- Direct PDF viewing from search results
- Dynamic mapping between local files and their original archives.gov URLs
- Automatic URL mapping during download process
- Verification tools to ensure archive links are valid
- Pattern-based document identification that works even with partial filenames
- Automatic redirection to archives.gov when local PDFs aren't available
- Support for different document collections (FBI files, State Department files, etc.)
-
Clone this repository:
git clone https://github.com/yourusername/govdocharvester.git cd govdocharvester -
Install the required dependencies:
pip install -r requirements.txt pip install -r requirements_ocr.txt -
Configure Tesseract and Poppler paths in
ocr_config.py:TESSERACT_PATH = r"C:\Program Files\Tesseract-OCR\tesseract.exe" # Update for your system POPPLER_PATH = r"C:\Program Files\poppler\bin" # Update for your system
List available pre-configured websites:
python download_site.py --list
Download PDFs from a specific collection:
python download_site.py rfk
Override the crawl depth or delay:
python download_site.py rfk --depth 4 --delay 2
Custom URL download:
python pdf_downloader.py https://www.archives.gov/research/rfk -o downloads/custom -d 3 --delay 1.0
First, verify your OCR setup:
python check_ocr_setup.py
Process PDFs with memory-efficient OCR (recommended):
run_ocr.bat --ocr rfk
Or manually with Python:
python run_pdf_search.py --ocr rfk --memory-limit 75 --workers 2
The system now automatically creates mappings between your PDFs and archives.gov URLs during the download process. However, you can also:
Verify existing archive links:
python run_pdf_search.py --verify-links
Regenerate mappings if needed:
python run_pdf_search.py --generate-mappings
Find actual PDF files on archives.gov and map them to local files:
python find_archive_pdfs.py
Launch the web search interface:
python web_app.py
Access the search interface in your browser:
http://127.0.0.1:5000
Now you can search through documents, and if a local PDF is not available, users will be redirected to the corresponding archives.gov page.
Edit the config.py file and add a new entry to the WEBSITE_CONFIGS dictionary:
"new_site_id": {
"url": "https://www.example.gov/documents",
"description": "Description of the document collection",
"output_dir": "downloads/new_site_id",
"depth": 3,
"delay": 1.0
}Edit the ocr_config.py file to adjust:
OCR_WORKERS: Number of parallel processing threadsMAX_MEMORY_PERCENT: Memory threshold to prevent crashes
Archive URL mappings are now generated automatically during download, but you can customize:
- Domain settings via
--domainparameter when downloading or regenerating mappings - Manual mappings by editing the
archive_mappings.jsonfile directly
pdf_downloader.py: Core PDF downloading functionality with automatic URL mappingdownload_site.py: Simplified interface for pre-configured sitesocr_processor.py: OCR processing for scanned PDFssearch_app.py: Search index creation and queryingweb_app.py: Web-based search and document viewing interfacearchive_mappings.py: URL mapping utility functionsfind_archive_pdfs.py: Tool to locate actual PDFs on archives.govrun_pdf_search.py: Combined control script with mapping validationcheck_ocr_setup.py: Diagnostic tool for OCR setup
- Research: Access and analyze historical government documents
- Journalism: Investigate government records databases
- Archiving: Create local searchable copies of important collections
- Legal: Build document collections for legal discovery
- Education: Provide access to primary source materials for students
- Always be considerate when crawling websites and respect their
robots.txtfiles - Large PDF collections may require significant disk space and processing time
- OCR quality depends on the quality of the original scans
- Make sure to use "archives.gov" (with an 's') as the domain for National Archives links
This project is ready for cloud deployment:
Procfileandrender.yamlfor easy deployment to Heroku or Renderprepare_for_deployment.pyscript to optimize for cloud environments- Separate requirements files for minimal production deployments
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with GitHub Copilot
- Special thanks to the Tesseract OCR project
- Uses Beautiful Soup for HTML parsing
- Search powered by Whoosh
- Web interface built with Flask
Empowering transparency through accessible public documents
