Read Jobylon's boards from the embed page and each role's page
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
68a3858355
commit
a41995da8e
6 files changed
+1694
No files matched your search
@@ -0,0 +1,216 @@
|
||||
"""Jobylon: `jobylon:<company id>`, the whole board in one HTML page, the
|
||||
description on each role's own page.
|
||||
|
||||
Written from Einride's board (company 3143) and Vipps MobilePay's (1056, no
|
||||
open roles) on 2026-09-29. Jobylon's own JSON and XML feeds are addressed by a
|
||||
uuid the company sets and holds, and none is public for these two, so the
|
||||
board is read from the widget's embed page, `cdn.jobylon.com/jobs/companies/
|
||||
<id>/embed/v2/`, which assigns `JBL.embed_v2['jobs'] = [...]` as a JavaScript
|
||||
literal with every open role (33 of 33 at Einride; `page_size` in the URL
|
||||
the widget is embedded with only sets its client-side page). The literal has
|
||||
unquoted keys and single-quoted strings, which `_json` reads. It carries no
|
||||
description, so `detail` reads the role's page on emp.jobylon.com, whose
|
||||
JSON-LD `JobPosting` has the description, the exact date and every location.
|
||||
A slug Jobylon does not know answers 404.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._shared import Get, Row, parse_dt
|
||||
|
||||
NAME = "jobylon"
|
||||
LABEL = "Jobylon"
|
||||
PATTERNS = (
|
||||
r"(?:emp|cdn)\.jobylon\.com/(?:jobs/)?companies/(\d+)",
|
||||
# A company's own site says which board it embeds (careers.einride.tech
|
||||
# sets `jbl_company_id = 3143`).
|
||||
r"jbl_company_id[\"']?\s*[=:]\s*[\"']?(\d+)",
|
||||
)
|
||||
|
||||
_CDN = "cdn.jobylon.com"
|
||||
_EMP = "emp.jobylon.com"
|
||||
|
||||
#: A company id, matched whole. The host names are fixed, so a slug can only
|
||||
#: ever land in a path.
|
||||
_SLUG = re.compile(r"[0-9]{1,12}")
|
||||
|
||||
#: A role's page on the site, as the embed names it (`/jobs/385191-einride-
|
||||
#: financial-controller/`): the only kind of link the module builds a URL
|
||||
#: from.
|
||||
_ROLE_PATH = re.compile(r"/jobs/[0-9]+(?:-[A-Za-z0-9_-]*)?/?")
|
||||
|
||||
_ASSIGNMENT = "JBL.embed_v2['jobs'] = "
|
||||
_KEY = re.compile(r"[A-Za-z_][A-Za-z0-9_]*")
|
||||
_TRAILING_COMMA = re.compile(r",(\s*[\]}])")
|
||||
|
||||
#: Jobylon's `workspace` -> `store._remote`'s words.
|
||||
_REMOTE = {"remote": "remote", "hybrid": "hybrid", "on-site": "onsite", "onsite": "onsite"}
|
||||
|
||||
#: The English month names, by their first three letters, in the spellings
|
||||
#: `published_date` uses ("Sept. 25, 2026").
|
||||
_MONTHS = {m: i for i, m in enumerate(
|
||||
("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"), 1)}
|
||||
_PUBLISHED = re.compile(r"([A-Za-z]{3})[A-Za-z]*\.? (\d{1,2}), (\d{4})")
|
||||
|
||||
|
||||
def slug_ok(slug: str) -> bool:
|
||||
return bool(_SLUG.fullmatch(slug))
|
||||
|
||||
|
||||
def allowed(slug: str) -> Callable[[str], bool]:
|
||||
return lambda host: host.lower() in (_CDN, _EMP)
|
||||
|
||||
|
||||
def careers_url(slug: str) -> str:
|
||||
"""Jobylon answers this with a redirect to `/companies/<id>-<name>/`."""
|
||||
return f"https://{_EMP}/companies/{slug}/"
|
||||
|
||||
|
||||
def feed_url(slug: str) -> str:
|
||||
return f"https://{_CDN}/jobs/companies/{slug}/embed/v2/"
|
||||
|
||||
|
||||
def robots_page(slug: str) -> str:
|
||||
"""The page the board is read from. Both hosts serve the same robots.txt
|
||||
(compared on 2026-09-29), so the roles' pages on emp.jobylon.com are
|
||||
covered by the check on this one."""
|
||||
return feed_url(slug)
|
||||
|
||||
|
||||
def _json(text: str) -> Any:
|
||||
"""A JavaScript array or object literal as JSON: keys quoted, strings
|
||||
single-quoted with `\\uXXXX` escapes, trailing commas."""
|
||||
out: list[str] = []
|
||||
i, n = 0, len(text)
|
||||
while i < n:
|
||||
char = text[i]
|
||||
if char in "'\"":
|
||||
i += 1
|
||||
chars: list[str] = []
|
||||
while i < n and text[i] != char:
|
||||
if text[i] == "\\":
|
||||
i += 1
|
||||
if text[i] == "u":
|
||||
chars.append(chr(int(text[i + 1:i + 5], 16)))
|
||||
i += 4
|
||||
elif text[i] == "x":
|
||||
chars.append(chr(int(text[i + 1:i + 3], 16)))
|
||||
i += 2
|
||||
else:
|
||||
chars.append({"n": "\n", "t": "\t", "r": "\r"}.get(text[i], text[i]))
|
||||
else:
|
||||
chars.append(text[i])
|
||||
i += 1
|
||||
i += 1
|
||||
out.append(json.dumps("".join(chars)))
|
||||
elif word := _KEY.match(text, i):
|
||||
i = word.end()
|
||||
colon = re.compile(r"\s*:").match(text, i)
|
||||
out.append(json.dumps(word.group()) if colon else word.group())
|
||||
else:
|
||||
out.append(char)
|
||||
i += 1
|
||||
return json.loads(_TRAILING_COMMA.sub(r"\1", "".join(out)))
|
||||
|
||||
|
||||
def _literal(body: bytes) -> str:
|
||||
"""The text of the jobs array: from its `[` to the matching `]`, quotes
|
||||
respected."""
|
||||
text = body.decode("utf-8", "replace")
|
||||
start = text.find(_ASSIGNMENT)
|
||||
if start < 0:
|
||||
raise ValueError("not a Jobylon board: no JBL.embed_v2['jobs'] in the page")
|
||||
start += len(_ASSIGNMENT)
|
||||
depth, i, quote = 0, start, ""
|
||||
while i < len(text):
|
||||
char = text[i]
|
||||
if quote:
|
||||
if char == "\\":
|
||||
i += 1
|
||||
elif char == quote:
|
||||
quote = ""
|
||||
elif char in "'\"":
|
||||
quote = char
|
||||
elif char == "[":
|
||||
depth += 1
|
||||
elif char == "]":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return text[start:i + 1]
|
||||
i += 1
|
||||
raise ValueError("Jobylon's jobs array does not end")
|
||||
|
||||
|
||||
def _published(value: Any) -> Any:
|
||||
match = _PUBLISHED.fullmatch(str(value or "").strip())
|
||||
month = _MONTHS.get(match.group(1).lower()) if match else None
|
||||
if not match or not month:
|
||||
return None
|
||||
return parse_dt(f"{match.group(3)}-{month:02d}-{int(match.group(2)):02d}")
|
||||
|
||||
|
||||
def parse(body: bytes, slug: str) -> list[Row]:
|
||||
"""The embed page -> one row per role. `posted` is the day `published_date`
|
||||
names, which `detail` replaces with the exact time. `location` joins the
|
||||
names the embed lists, which can be fewer than the role's places
|
||||
("Houston +3 more" lists three); `detail` has them all. The embed states
|
||||
no pay. `department` is the role's `function`, unless it is the
|
||||
placeholder "All functions"."""
|
||||
out = []
|
||||
for j in _json(_literal(body)):
|
||||
title = (j.get("title") or "").strip()
|
||||
job_id = str(j.get("id") or "").strip()
|
||||
path = str(j.get("url") or "").strip()
|
||||
if not title or not job_id or not _ROLE_PATH.fullmatch(path):
|
||||
continue
|
||||
function = str(j.get("function") or "").strip()
|
||||
out.append({
|
||||
"source_id": job_id,
|
||||
"title": title,
|
||||
"location": "; ".join(dict.fromkeys(
|
||||
str(name).strip() for name in j.get("locations") or [] if str(name).strip())),
|
||||
"url": f"https://{_EMP}{path}",
|
||||
"posted": _published(j.get("published_date")),
|
||||
"department": "" if function == "All functions" else function,
|
||||
"description": "",
|
||||
"remote": _REMOTE.get(str(j.get("workspace") or "").strip().lower()),
|
||||
"salary_text": "", # the embed states no pay
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
|
||||
"""The role's own page: its JSON-LD `JobPosting` has the description, the
|
||||
time it was posted and each place as "Houston, TX, USA"."""
|
||||
page = get(row["url"], headers={"Accept": "text/html"}).decode("utf-8", "replace")
|
||||
for block in re.findall(r'<script type="application/ld\+json"[^>]*>(.*?)</script>',
|
||||
page, re.S):
|
||||
try:
|
||||
data = json.loads(block, strict=False)
|
||||
except ValueError:
|
||||
continue
|
||||
if isinstance(data, dict) and data.get("@type") == "JobPosting":
|
||||
break
|
||||
else:
|
||||
raise ValueError("no JobPosting on the role's page")
|
||||
places = []
|
||||
for place in data.get("jobLocation") or []:
|
||||
address = (place or {}).get("address") or {}
|
||||
name = str(address.get("streetAddress") or address.get("addressLocality") or "").strip()
|
||||
if name and name not in places:
|
||||
places.append(name)
|
||||
found: dict[str, Any] = {
|
||||
"description": html.unescape(strip_html(data.get("description") or "")),
|
||||
"posted": parse_dt(data.get("datePosted")),
|
||||
}
|
||||
if places:
|
||||
found["location"] = "; ".join(places)
|
||||
return found
|
||||
Reference in new issue
Block a user