Search CivilJobs for a departmental reference using the site's direct query-parameter filter and return matching vacancy links and titles.
Use Cases
Use when the caller provides a CivilJobs departmental reference such as {reference} and needs to determine whether it identifies a vacancy, optionally checking its title.
Automation Flow
- Navigate directly to
https://civiljobs.co.uk/?q={url-encoded-reference}. Theqparameter initializes the same client-side filtering performed by the homepage search field; do not visit the homepage or type into the field separately. - Wait approximately 2.2 seconds for the client-side vacancy filtering to finish.
- Run this evaluator on the loaded page, substituting the caller's values for
{reference}and the optional{title-pattern}(a case-insensitive regular expression such asteam leader; leave it empty to skip title filtering):
(() => {
const reference = "{reference}";
const titlePattern = "{title-pattern}";
const matches = [...new Map(
[...document.querySelectorAll('a[href*="/jobs/"]')]
.map(a => ({
href: new URL(a.getAttribute('href'), location.origin).href,
title: a.textContent.replace(/\s+/g, ' ').trim()
}))
.filter(x => /\/jobs\/.*ref-\d+/i.test(x.href))
.filter(x => (x.href + " " + x.title).toLowerCase().includes(reference.toLowerCase()))
.map(x => [x.href, x])
).values()];
return {
reference,
found: matches.length > 0,
matches,
titleMatches: titlePattern ? matches.filter(x => new RegExp(titlePattern, "i").test(x.title)) : matches
};
})()Possible Friction Points
- CivilJobs filtering is client-side, but
https://civiljobs.co.uk/?q={reference}directly reaches the filtered state and avoids homepage interaction. - URL-encode the reference when constructing the
qparameter. - Wait for the dynamic filter to update before extracting results.
- The search input, useful as a fallback if direct
qinitialization ever fails, isinput#filter-search; setting its value must dispatch aninputevent. - Vacancy links use
/jobs/paths containing aref-{digits}segment. Restrict extraction to those links rather than treating every/jobs/link as a result.