From d685a6236c86df0600d963c06fbd1754378b6d13 Mon Sep 17 00:00:00 2001 From: Matthew M-B Date: Sat, 19 Oct 2024 12:58:53 -0400 Subject: [PATCH] Add example code for webscraping --- .../2024-2025/challenges/11-web-scraper.md | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/content/hackthetunnels/2024-2025/challenges/11-web-scraper.md b/content/hackthetunnels/2024-2025/challenges/11-web-scraper.md index ea0934964..d06078ebe 100644 --- a/content/hackthetunnels/2024-2025/challenges/11-web-scraper.md +++ b/content/hackthetunnels/2024-2025/challenges/11-web-scraper.md @@ -14,9 +14,24 @@ preview: "images/event_posters/2023-2024/hack_the_tunnels.jpg" Create a web scraper that extracts course data from the [Carleton Central schedule page](https://central.carleton.ca/prod/bwysched.p_select_term?wsea_code=EXT). The scraper should retrieve details such as course codes, titles, and available sections for a given term. -If you're not sure where to get started, see this [guide. -](https://www.freecodecamp.org/news/the-ultimate-guide-to-web-scraping-with-node-js-daa2027dcd3/) -
+If you're not sure where to get started, here is some starter code: + +```typescript +import axios from 'axios'; +import * as cheerio from 'cheerio'; // Use this syntax for compatibility + +const scrapeData = async () => { + const { data } = await axios.get('https://central.carleton.ca/prod/bwysched.p_select_term?wsea_code=EXT'); + console.log(data); // Logs raw HTML content + + const $ = cheerio.load(data); // Initialize Cheerio with loaded HTML + console.log($('title').text()); // Example: Print the content +}; + +scrapeData(); +``` + +To run this code, you'll have to `npm i axios` and `npm i cheerio`. ## Acceptance Criteria: