You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB
Python

"""PDS Health adapter — Angular Material job board, URL-based pagination."""
from __future__ import annotations
import re
from loguru import logger
from gimme_job.adapters.base import ManifestDrivenAdapter
from gimme_job.adapters.registry import register
from gimme_job.models.dto import JobPostingCandidate, RawJobCard
@register("pdshealth")
class PdsHealthAdapter(ManifestDrivenAdapter):
def _wait_for_results(self, page) -> None:
try:
page.wait_for_selector(
"mat-expansion-panel.search-result-item",
timeout=15000,
state="attached",
)
except Exception:
logger.debug("[pdshealth] Results wait timed out — may be zero results")
def collect_cards(self, page, manifest):
self._wait_for_results(page)
return super().collect_cards(page, manifest)
def paginate(self, page, page_index: int, config) -> bool:
"""Navigate to next page by incrementing the &page= URL parameter."""
max_pages = config.pagination.max_pages
if page_index >= max_pages - 1:
return False
current_url = page.url
next_page = page_index + 2 # 0-based index → 1-based page param
if re.search(r"[?&]page=\d+", current_url):
next_url = re.sub(r"(page=)\d+", f"page={next_page}", current_url)
else:
sep = "&" if "?" in current_url else "?"
next_url = f"{current_url}{sep}page={next_page}"
logger.debug(f"[pdshealth] Paginating to page {next_page}: {next_url}")
page.goto(next_url, timeout=30000)
self._wait_for_results(page)
return True