169 lines
6.9 KiB
Python
169 lines
6.9 KiB
Python
"""Deel: `deel:<slug>` for jobs.deel.com/<slug>, the whole board in one HTML
|
|
page.
|
|
|
|
Written from Klarna's board on 2026-09-29. Deel's job board is a Next.js page
|
|
with no public JSON endpoint (its `/api/` is disallowed by robots.txt), but
|
|
the server-rendered page carries the board in its React Server Components
|
|
payload: a stream of `self.__next_f.push([1, "..."])` scripts whose strings,
|
|
joined, hold `"jobPostings":[...]` with every open role, and, beside it, the
|
|
rich-text descriptions as separate text rows that a posting names by
|
|
reference (`"richtextDescription":"$1a"`). Klarna's 96 roles came in one
|
|
page, the same 96 as the page's own JSON-LD list, so no description needs a
|
|
read of the role's page.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import html
|
|
import json
|
|
import logging
|
|
import re
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from desk.sources import strip_html
|
|
|
|
from ._contract import Ask, Fields, Reads, Row
|
|
from ._shared import num, only, parse_dt, pay_line
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
READS = Reads(
|
|
scope="board", listing="whole", text="listing", complete="whole",
|
|
places="many",
|
|
fields=Fields(pay="line", posted="listed", remote="stated", employment="stated"),
|
|
robots="read: robots.txt allows the board page /<slug>; /api/ is disallowed and not read "
|
|
"(checked 2026-09-29)",
|
|
)
|
|
|
|
NAME = "deel"
|
|
LABEL = "Deel"
|
|
KEEP_CASE = True # `jobs.deel.com/Klarna` is "Job Board Not Found", `/klarna` is the board
|
|
PATTERNS = (
|
|
# `/job-boards/<slug>` is the address Klarna's own site links to.
|
|
r"jobs\.deel\.com/(?:job-boards/)?(?!job-boards\b)([A-Za-z0-9][A-Za-z0-9_-]*)",
|
|
)
|
|
|
|
_HOST = "jobs.deel.com"
|
|
|
|
#: A slug is one path segment that starts with a letter or a digit, so `_next`
|
|
#: and `.` never name a board.
|
|
_SLUG = re.compile(r"[A-Za-z0-9][A-Za-z0-9_-]*")
|
|
|
|
#: One script of the payload, its JSON string literal captured. Kind 1 is
|
|
#: the data; the others (`[0]`, `[2, ...]`) carry the bootstrap.
|
|
_PUSH = re.compile(r'self\.__next_f\.push\(\[1,("(?:[^"\\]|\\.)*")\]\)')
|
|
|
|
#: One row of the joined stream: `<hex id>:` and then either `T<hex length>,`
|
|
#: and that many bytes of text, or a line of JSON.
|
|
_ROW = re.compile(rb"([0-9a-f]*):")
|
|
_TEXT = re.compile(rb"T([0-9a-f]+),")
|
|
|
|
|
|
def slug_ok(slug: str) -> bool:
|
|
return bool(_SLUG.fullmatch(slug))
|
|
|
|
|
|
def allowed(slug: str) -> Callable[[str], bool]:
|
|
return only(_HOST)
|
|
|
|
|
|
def careers_url(slug: str) -> str:
|
|
return f"https://{_HOST}/{slug}"
|
|
|
|
|
|
def feed_url(slug: str, ask: Ask) -> str:
|
|
return careers_url(slug)
|
|
|
|
|
|
def _stream(body: bytes) -> dict[str, str]:
|
|
"""The payload's rows by id. A text row's length is in bytes of UTF-8 and
|
|
the next row follows it directly, so the stream is read as bytes, one row
|
|
after another, rather than split on newlines."""
|
|
text = "".join(json.loads(m.group(1)) for m in _PUSH.finditer(body.decode("utf-8", "replace")))
|
|
data = text.encode()
|
|
out: dict[str, str] = {}
|
|
pos = 0
|
|
while pos < len(data) and (row := _ROW.match(data, pos)):
|
|
pos = row.end()
|
|
if data[pos:pos + 1] == b"T" and (size := _TEXT.match(data, pos)):
|
|
end = size.end() + int(size.group(1), 16)
|
|
out[row.group(1).decode()] = data[size.end():end].decode("utf-8", "replace")
|
|
pos = end
|
|
else:
|
|
end = data.find(b"\n", pos)
|
|
end = len(data) if end < 0 else end
|
|
out[row.group(1).decode()] = data[pos:end].decode("utf-8", "replace")
|
|
pos = end + 1
|
|
return out
|
|
|
|
|
|
def _postings(body: bytes) -> tuple[list[dict[str, Any]], dict[str, str]]:
|
|
"""The board's postings and the stream they refer into. A page without
|
|
the postings array is not a board (a slug Deel does not know answers
|
|
"Job Board Not Found"), and raises rather than read as an empty board."""
|
|
stream = _stream(body)
|
|
for value in stream.values():
|
|
start = value.find('"jobPostings":[')
|
|
if start >= 0:
|
|
postings, _end = json.JSONDecoder().raw_decode(value[start + len('"jobPostings":'):])
|
|
return postings, stream
|
|
raise ValueError("not a Deel job board: no jobPostings in the page")
|
|
|
|
|
|
def _employment(job: dict[str, Any]) -> str | None:
|
|
"""The name of the first `jobEmploymentTypes` entry that has one."""
|
|
for entry in job.get("jobEmploymentTypes") or []:
|
|
name = ((entry or {}).get("employmentType") or {}).get("name")
|
|
if found := str(name or "").strip():
|
|
return found
|
|
return None
|
|
|
|
|
|
def parse(body: bytes, slug: str) -> list[Row]:
|
|
"""`jobs.deel.com/<slug>` -> one row per posting. `location` joins the
|
|
role's places with "; ", and `places` lists each. `posted` is the day the posting was published
|
|
(its publication's state), not the day the role was drafted.
|
|
|
|
Deel states pay as a currency and two amounts with no period, and the
|
|
amounts run from 775,398 SEK to 55,206 SEK on one board, the latter
|
|
plainly a month's pay. A yearly figure cannot be told from a monthly one,
|
|
so the columns stay empty and `salary_text` gives the range as stated."""
|
|
postings, stream = _postings(body)
|
|
out = []
|
|
for p in postings:
|
|
title = (p.get("title") or "").strip()
|
|
post_id = str(p.get("id") or "")
|
|
if not title or not post_id:
|
|
continue
|
|
job = p.get("job") or {}
|
|
places = [name for loc in job.get("jobLocations") or []
|
|
if (name := ((loc.get("location") or {}).get("name") or "").strip())]
|
|
departments = [name for d in job.get("jobDepartments") or []
|
|
if (name := ((d.get("department") or {}).get("name") or "").strip())]
|
|
pay = job.get("currentCompensation") or {}
|
|
published = ((p.get("jobPostingPublications") or [{}])[0].get("currentState") or {})
|
|
description = p.get("richtextDescription") or ""
|
|
if description.startswith("$"):
|
|
description = stream.get(description[1:], "")
|
|
arrangement = str(job.get("workArrangementEnum") or "").strip()
|
|
remote = {"REMOTE": True, "HYBRID": False, "ON_SITE": False}.get(arrangement)
|
|
row: Row = {
|
|
"source_id": post_id,
|
|
"title": title,
|
|
"places": [{"text": name, "remote": remote} for name in dict.fromkeys(places)],
|
|
"location": "; ".join(dict.fromkeys(places)),
|
|
"url": f"https://{_HOST}/{slug}/job-details/{post_id}/overview",
|
|
"posted": parse_dt(published.get("createdAt") or p.get("createdAt")),
|
|
"department": ", ".join(dict.fromkeys(departments)),
|
|
"description": html.unescape(strip_html(description)),
|
|
"remote": arrangement or None,
|
|
"salary_text": (pay_line(num(pay.get("minAmount")), num(pay.get("maxAmount")),
|
|
pay.get("currencyIsoCode"), "")
|
|
if p.get("isCompensationVisible") else ""),
|
|
}
|
|
if employment := _employment(job):
|
|
row["employment"] = employment
|
|
out.append(row)
|
|
return out
|