Playwright-based scraper implementation for The Pudim Hunter platform
Project description
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
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:
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:
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.
-
ScraperJobDriver(ABC) - The base scraper class that implementsJobDriver:build_search_url(query: JobQuery) -> strget_selectors() -> Dict[str, str]extract_raw_job_data() -> Optional[List[Dict[str, Any]]]transform_job(data: Dict[str, Any]) -> Optional[Job]
-
PlaywrightScraper- The base scraper implementation:- Handles browser lifecycle
- Provides navigation and data extraction methods
- Context manager support with
withstatement
-
PhantomPlaywrightScraper- Enhanced scraper with anti-detection:- All features of base PlaywrightScraper
- Advanced bot detection evasion
- Stealth mode configurations
-
Exceptions:
- Inherits all exceptions from
pudim-hunter-driver - Adds scraper-specific error handling
- Inherits all exceptions from
Example Implementation
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
# 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 exampletests/test_scraper_phantom.py: Anti-detection features testingtests/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
- Create and activate virtual environment:
python3.9 -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
pip install -e .
- Install Playwright browsers:
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:
pytest tests/
Key test files:
test_driver_phantom.py: Tests for phantom job driver implementationtest_scraper_phantom.py: Tests for anti-detection capabilitiestest_scraper_phantom_sites.py: Tests for real-world site scraping
Contributing
Getting Started
- Fork and clone the repository:
git clone git@github.com:luismr/pudim-hunter-driver-scraper.git
cd pudim-hunter-driver-scraper
- Create your feature branch:
git checkout -b feature/amazing-feature
- Set up development environment:
python3.9 -m venv venv
source venv/bin/activate
pip install -e .
Pull Request Process
- Update documentation as needed
- Add/update tests as needed
- Ensure all tests pass
- Submit PR for review
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Copyright (c) 2024-2025 Luis Machado Reis
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pudim-hunter-driver-scraper-0.0.17.tar.gz.
File metadata
- Download URL: pudim-hunter-driver-scraper-0.0.17.tar.gz
- Upload date:
- Size: 780.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7aaa3fb77fd45eaa00c88112086432c1fa227149a691fb595eb4d93d1713d4b8
|
|
| MD5 |
403d9dda459738a5d82326319e7e4675
|
|
| BLAKE2b-256 |
84019857e0d6bb360e195fe4b712dd5945877e6b6fb5be021287d8f249d90e00
|
File details
Details for the file pudim_hunter_driver_scraper-0.0.17-py3-none-any.whl.
File metadata
- Download URL: pudim_hunter_driver_scraper-0.0.17-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c8221c8ef63f32fc75dda36a9650197bcf4c2e091c4541bd238bd726b00e965
|
|
| MD5 |
311c943c701a417939fc3789bb7328f3
|
|
| BLAKE2b-256 |
aae87ae7a69ed517610df65c6aa8c466ffef6666fcd738265c36ee96c6b5a76a
|