Created
January 5, 2024 20:49
-
-
Save ggorlen/318310dfb34609455781cdbd64abd4ca to your computer and use it in GitHub Desktop.
Scrape SFPL hours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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