diff --git a/plugins/readers/jobindex.py b/plugins/readers/jobindex.py index c7bb7ce..af4f881 100644 --- a/plugins/readers/jobindex.py +++ b/plugins/readers/jobindex.py @@ -15,6 +15,13 @@ the paragraphs are an excerpt of the ad, handed over as `teaser`. A crawled ad ("robot job") has no logo, so its company is what follows the title's last comma, or '' when there is none. An answer with no `` is not a search result and raises, since an empty list would read as a search that ran out. + +The `` opens Jobindex's `vis-job` page, and `posting_link` reads the +"Se jobbet" button on it: the employer's site, The Hub or Jobindex's own +`jobannonce`, checked on 2026-09-30. It is not part of the search: fetching +that page counts as a click in Jobindex's statistics, so `app.jobs.posting` +does it only for a role somebody opened. The page's "other ads" cards carry +the same words on `/c?t=` redirects, which are not this ad and are skipped. """ from __future__ import annotations @@ -24,7 +31,7 @@ import re import xml.etree.ElementTree as ET from collections.abc import Callable from typing import Any -from urllib.parse import urlencode +from urllib.parse import urlencode, urljoin, urlsplit from desk.sources import strip_html @@ -62,6 +69,8 @@ _AREA = re.compile(r'class="jix_robotjob--area">(.*?)', re.IGNORECASE | r _PARAGRAPHS = re.compile(r"

(.*?)

", re.IGNORECASE | re.DOTALL) #: "Ledige job i Region Hovedstaden indeholdende ..." -> "Region Hovedstaden". _SEARCH_AREA = re.compile(r"Ledige job i (.+?) indeholdende") +_SE_JOBBET = re.compile(r"]*)>\s*Se jobbet\s*", re.IGNORECASE) +_HREF = re.compile(r'\bhref\s*=\s*"([^"]*)"', re.IGNORECASE) def allowed(slug: str) -> Callable[[str], bool]: @@ -77,6 +86,20 @@ def clean_params(params: dict[str, Any]) -> dict[str, Any]: return out +def posting_link(page_html: str) -> str: + """The "Se jobbet" link of a `vis-job` page: where the ad itself is, as an + absolute URL, or '' when the page has none. A `/c?t=` link is another ad's + redirect and is skipped.""" + for tag in _SE_JOBBET.finditer(page_html): + found = _HREF.search(tag.group(1)) + if not found: + continue + url = urljoin("https://www.jobindex.dk/", html.unescape(found.group(1)).strip()) + if is_web_url(url) and urlsplit(url).path != "/c": + return url + return "" + + def _text(fragment: str) -> str: """HTML to plain text. Jobindex breaks titles after a slash with a zero-width space, which would otherwise end up in `title_key`.""" diff --git a/tests/fixtures/jobindex/vis-job-employer.html b/tests/fixtures/jobindex/vis-job-employer.html new file mode 100644 index 0000000..392e8ef --- /dev/null +++ b/tests/fixtures/jobindex/vis-job-employer.html @@ -0,0 +1,32 @@ + + + + Løsningsarkitekt til Købstædernes Forsikring - 1702752 | Jobindex + + + + + +
+
+ + + + + + Gem job + + + + + Se jobbet + + +
+ Se jobbet + +
+ + + + diff --git a/tests/fixtures/jobindex/vis-job-jobannonce.html b/tests/fixtures/jobindex/vis-job-jobannonce.html new file mode 100644 index 0000000..f34707d --- /dev/null +++ b/tests/fixtures/jobindex/vis-job-jobannonce.html @@ -0,0 +1,114 @@ + + + + Lead Software Engineer - Research Tech Delivery, AI & Digital Innovation - 14009457 | Jobindex + + + + + +
+
+ + + + + + Gem job + + + + + Se jobbet + + +
+ Se jobbet + +
+ + + + + + + + + + + + + + + + +
+ +
+
+ + + + + + Gem job + + + + + Se jobbet + + +
+ Se jobbet + +
+ + + + + + + + + + + + +
+ + +
+