Read the Se jobbet link off a Jobindex vis-job page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a19c528e3f
commit
54b56ac370
5 files changed
+300
-1
No files matched your search
@@ -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 `<channel>` is not a search
|
||||
result and raises, since an empty list would read as a search that ran out.
|
||||
|
||||
The `<link>` 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">(.*?)</span>', re.IGNORECASE | r
|
||||
_PARAGRAPHS = re.compile(r"<p>(.*?)</p>", 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"<a\b([^>]*)>\s*Se jobbet\s*</a>", 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`."""
|
||||
|
||||
Reference in new issue
Block a user