Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Created January 5, 2024 20:49
Show Gist options
  • Save ggorlen/318310dfb34609455781cdbd64abd4ca to your computer and use it in GitHub Desktop.
Save ggorlen/318310dfb34609455781cdbd64abd4ca to your computer and use it in GitHub Desktop.
Scrape SFPL hours
// copy and paste url into browser and run code in console
// probably use puppeteer rather than fetch if you want to automate this
// (pagination doesn't seem to work with requests, maybe user agent? dunno why)
var url =
"https://sfpl.org/locations/#!/filters?sort_by=weight&sort_order=ASC&items_per_page=50";
var hours = [...document.querySelectorAll(".location--teaser--inner")]
.map(e => ({
name: e.querySelector(".location__title").textContent.trim(),
hours: [...e.querySelectorAll(".office-hours__item")].map(
e => e.textContent.replace(/\s+/g, " ").trim()
),
address: e.querySelector(".address").textContent.trim(),
}))
.filter(e => !/virtual/i.test(e.name));
console.log(hours);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment