Back

Version 2

4/22/2024
import cheerio from "npm:cheerio";

const FARGO_GOLF_URL = "https://foreupsoftware.com/index.php/booking/a/19956/18#/teetimes";

function normalizeURL(url: string) {
return url.startsWith("http://") || url.startsWith("https://")
? url
: "http://" + url;
}

async function fetchText(url: string, options?: any) {
const response = await fetch(normalizeURL(url), {
redirect: "follow",
...(options || {}),
});

return response.text();
}

const daysSelector = "td.day:not(.disabled), td.active.day:not(.disabled)";
const teeTimesListSelector = ".times-inner";

export const webScrapeTeeTimes = async () => {
const html = await fetchText(FARGO_GOLF_URL);
const $ = cheerio.load(html);

document.querySelector("#content > div > button").click();

const availableDays = document.querySelectorAll(daysSelector);
// code to select the destired day here
const availableTeeTimes = $(".time-tile-ob-no-details");
console.log(availableTeeTimes.length);

// const teeTimes = [];
// availableTeeTimes.forEach((teeTime) => {
// const time = teeTime.querySelector('times-booking-start-time-label');
Updated: April 29, 2024