Skip to content

Fetch many postings efficiently

Some boards (Ashby, Lever, Shopify) only hand over full postings through their jobs list endpoint. You don’t need to know which: Scraper.getJob fetches the list behind the scenes when its cache is cold, so a job is always fetchable at will.

However, for bulk work, that strategy can be wasteful. listCompanyJobs and fetchJob each build a scraper instance and dispose of it before returning, which drops whatever it cached (notably the job list some boards need to answer getJobContent from). Fine for one lookup, but when fetching many jobs from the same company, it’s more efficient to hold onto a scraper instance yourself instead:

import {
  createScraper,
  renderScrapedPosting,
  resolveCompany,
} from '@chrisdothtml/job-scraper';

async function printMatchingJobs(companyName: string, titlePart: string) {
  const company = await resolveCompany(companyName);
  const scraper = createScraper(company);

  try {
    const listedJobs = await scraper.getJobsList();
    for (const listed of listedJobs) {
      if (!listed.title.toLowerCase().includes(titlePart.toLowerCase()))
        continue;

      const job = await scraper.getJob(listed.id);
      const rendered = renderScrapedPosting(
        { ...job, ...listed },
        { postingUrl: listed.url }
      );
      console.log(rendered.markdown);
    }
  } finally {
    scraper.dispose();
  }
}

await printMatchingJobs('Airbnb', 'engineer');