Metadata-Version: 2.1
Name: pudim-hunter-driver-scraper
Version: 0.0.17
Summary: Playwright-based scraper implementation for The Pudim Hunter platform
Author-email: The Pudim Hunter Team <luis.reis@gmail.com>
License: MIT
Project-URL: Source, https://github.com/luismr/pudim-hunter-driver-scraper
Project-URL: Bug Tracker, https://github.com/luismr/pudim-hunter-driver-scraper/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: pudim-hunter-driver>=0.0.8
Requires-Dist: playwright>=1.41.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pytest>=7.4.0
Requires-Dist: pytest-asyncio>=0.21.0
Requires-Dist: pytest-cov>=4.1.0
Requires-Dist: black>=23.0.0
Requires-Dist: flake8>=6.0.0
Requires-Dist: mypy>=1.0.0
Requires-Dist: isort>=5.12.0
Requires-Dist: wheel>=0.40.0
Requires-Dist: setuptools==69.2.0
Requires-Dist: setuptools-scm[toml]==8.0.0
Requires-Dist: twine>=4.0.2
Requires-Dist: build>=1.0.3

# Pudim Hunter Driver Scraper 🍮

[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Pytest 7.4](https://img.shields.io/badge/pytest-7.4-brightgreen.svg)](https://docs.pytest.org/en/7.4.x/)
[![CI](https://github.com/luismr/pudim-hunter-driver-scraper/actions/workflows/ci.yml/badge.svg)](https://github.com/luismr/pudim-hunter-driver-scraper/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/luismr/pudim-hunter-driver-scraper/branch/main/graph/badge.svg)](https://codecov.io/gh/luismr/pudim-hunter-driver-scraper)
[![PyPI version](https://badge.fury.io/py/pudim-hunter-driver-scraper.svg)](https://pypi.org/project/pudim-hunter-driver-scraper/)

A Python package that provides a Playwright-based scraper implementation for The Pudim Hunter platform. This package extends the `pudim-hunter-driver` interface to provide a common base for implementing job board scrapers.

## Table of Contents

1. [Features](#features)
2. [Installation](#installation)
   - [PyPI Installation](#pypi-installation)
   - [Development Installation](#development-installation)
3. [Usage](#usage)
   - [Interface Overview](#interface-overview)
   - [Example Implementation](#example-implementation)
   - [Usage Examples](#usage-examples)
4. [Development Setup](#development-setup)
   - [Virtual Environment](#virtual-environment)
   - [Prerequisites](#prerequisites)
   - [Setup Instructions](#setup-instructions)
5. [Project Structure](#project-structure)
6. [Testing](#testing)
7. [Contributing](#contributing)
   - [Getting Started](#getting-started)
   - [Pull Request Process](#pull-request-process)
8. [License](#license)

## Features

* Playwright-based web scraping
* Headless browser automation
* Easy-to-extend base classes for job board implementations
* Built-in error handling and resource management
* Type hints and validation using Pydantic
* Advanced anti-detection scraping with `PhantomPlaywrightScraper`
  - WebDriver detection evasion
  - WebGL vendor spoofing
  - Chrome properties emulation
  - Plugin spoofing
  - Language preferences customization
  - And more stealth features

## Installation

### PyPI Installation

You can install the package directly from PyPI:

```bash
pip install pudim-hunter-driver-scraper
```

Or add to your requirements.txt:
```
pudim-hunter-driver-scraper>=0.0.1  # Replace with the version you need
```

### Development Installation

For development:
```bash
git clone git@github.com:luismr/pudim-hunter-driver-scraper.git
cd pudim-hunter-driver-scraper
pip install -e .
```

## Usage

### Interface Overview

This package provides the base scraper implementation for job search drivers. To create a scraper for a specific job board, you'll need to extend the `ScraperJobDriver` class and implement the required methods.

1. `ScraperJobDriver` (ABC) - The base scraper class that implements `JobDriver`:
   * `build_search_url(query: JobQuery) -> str`
   * `get_selectors() -> Dict[str, str]`
   * `extract_raw_job_data() -> Optional[List[Dict[str, Any]]]`
   * `transform_job(data: Dict[str, Any]) -> Optional[Job]`

2. `PlaywrightScraper` - The base scraper implementation:
   * Handles browser lifecycle
   * Provides navigation and data extraction methods
   * Context manager support with `with` statement

3. `PhantomPlaywrightScraper` - Enhanced scraper with anti-detection:
   * All features of base PlaywrightScraper
   * Advanced bot detection evasion
   * Stealth mode configurations

4. Exceptions:
   * Inherits all exceptions from `pudim-hunter-driver`
   * Adds scraper-specific error handling

### Example Implementation

```python
from typing import Dict, Any, Optional, List
from pudim_hunter_driver.models import JobQuery, Job
from pudim_hunter_driver_scraper import ScraperJobDriver
from pudim_hunter_driver_scraper.driver import ScraperType

class MyPhantomJobDriver(ScraperJobDriver):
    def __init__(self):
        super().__init__(scraper_type=ScraperType.PHANTOM)
    
    def build_search_url(self, query: JobQuery) -> str:
        """Build the search URL for the job board."""
        return f"https://example.com/jobs?q={query.keywords}&l={query.location}"
    
    def get_selectors(self) -> Dict[str, str]:
        """Define CSS selectors for job elements."""
        return {
            "job_list": ".job-listing",
            "title": ".job-title",
            "company": ".company-name",
            "location": ".job-location"
        }
    
    def extract_raw_job_data(self) -> Optional[List[Dict[str, Any]]]:
        """Extract job data from the page."""
        jobs_data = []
        job_elements = self.scraper._page.query_selector_all(self.get_selectors()["job_list"])
        
        for job in job_elements:
            title = job.query_selector(self.get_selectors()["title"])
            company = job.query_selector(self.get_selectors()["company"])
            
            if title and company:
                jobs_data.append({
                    "title": title.inner_text(),
                    "company": company.inner_text()
                })
        
        return jobs_data
    
    def transform_job(self, data: Dict[str, Any]) -> Optional[Job]:
        """Transform raw job data into Job model."""
        if not data.get("title"):
            return None
            
        return Job(
            id=f"job-{hash(data['title'])}",
            title=data["title"],
            company=data["company"],
            location="",
            description="",
            url="",
            remote=False,
            source="Example",
            posted_at=datetime.now()
        )
```

### Usage Examples

```python
# Using the driver
driver = MyPhantomJobDriver()
query = JobQuery(
    keywords="software engineer",
    location="San Francisco",
    page=1,
    items_per_page=20
)

job_list = driver.fetch_jobs(query)
for job in job_list.jobs:
    print(f"{job.title} at {job.company}")
```

For more detailed examples, check the test files:
- `tests/test_driver_phantom.py`: Complete job driver implementation example
- `tests/test_scraper_phantom.py`: Anti-detection features testing
- `tests/test_scraper_phantom_sites.py`: Real-world site scraping examples

## Development Setup

### Virtual Environment

We strongly recommend using a virtual environment for development and testing.

### Prerequisites

* Python 3.9 or higher
* pip (Python package installer)
* venv module (usually comes with Python 3)

### Setup Instructions

1. Create and activate virtual environment:
```bash
python3.9 -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate
```

2. Install dependencies:
```bash
pip install -r requirements.txt
pip install -e .
```

3. Install Playwright browsers:
```bash
playwright install chromium
```

## Project Structure

```
pudim-hunter-driver-scraper/
├── src/
│   └── pudim_hunter_driver_scraper/
│       ├── __init__.py          # Package initialization
│       ├── scraper.py           # PlaywrightScraper implementation
│       └── driver.py            # ScraperJobDriver implementation
├── tests/                       # Test directory
│   └── __init__.py
├── README.md                    # This file
├── requirements.txt             # Direct dependencies
├── setup.py                     # Package setup
└── pyproject.toml              # Project configuration
```

## Testing

Run the tests:
```bash
pytest tests/
```

Key test files:
- `test_driver_phantom.py`: Tests for phantom job driver implementation
- `test_scraper_phantom.py`: Tests for anti-detection capabilities
- `test_scraper_phantom_sites.py`: Tests for real-world site scraping

## Contributing

### Getting Started

1. Fork and clone the repository:
```bash
git clone git@github.com:luismr/pudim-hunter-driver-scraper.git
cd pudim-hunter-driver-scraper
```

2. Create your feature branch:
```bash
git checkout -b feature/amazing-feature
```

3. Set up development environment:
```bash
python3.9 -m venv venv
source venv/bin/activate
pip install -e .
```

### Pull Request Process

1. Update documentation as needed
2. Add/update tests as needed
3. Ensure all tests pass
4. Submit PR for review

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

Copyright (c) 2024-2025 Luis Machado Reis 
