Avatar

radarthreat

2 public vals
Joined July 18, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
window.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');
// const course = teeTime.querySelector('times-booking-teesheet-name');
// const playerCount = teeTime.querySelector('time-summary-ob-player-count');
// });
// const latestIssueSection = $("main > :nth-child(2)");
// const title = latestIssueSection
// .find("a")
// .children()
// .eq(1)
// .find("h3")
// .children()
// .eq(1)
// .text();
// const articleNumber = latestIssueSection
// .find("a")
// .children()
// .eq(1)
// .find("h3")
// .children()
// .eq(0)
// .text();
// const date = latestIssueSection
// .find("a")
// .children()
// .eq(1)
// .find("div > div > span")
// .text();
// return {
// id: Number(articleNumber.split(" ")[1]),
// title,
// date,
// };
};
webScrapeTeeTimes();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { lowercaseKeys } from "https://esm.town/v/stevekrouse/lowercaseKeys";
import { normalizeURL } from "https://esm.town/v/stevekrouse/normalizeURL";
export const fetchJSON = async (
url: string,
options?: RequestInit & {
bearer?: string;
},
) => {
let f = await fetch(normalizeURL(url), {
redirect: "follow",
...options,
headers: {
"content-type": "application/json",
authorization: options?.bearer ? `Bearer ${options.bearer}` : undefined,
...(lowercaseKeys(options?.headers ?? {})),
},
});
let t = await f.text();
try {
return JSON.parse(t);
}
catch (e) {
throw new Error(`fetchJSON error: ${e.message} in ${url}\n\n"${t}"`);
}
};
Next