forked from sciocaptain/fitwolves
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjsScraper.js
More file actions
37 lines (30 loc) · 1.04 KB
/
jsScraper.js
File metadata and controls
37 lines (30 loc) · 1.04 KB
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
const puppeteer = require('puppeteer');
async function scrapeMenuItems() {
// Launch a headless browser
const browser = await puppeteer.launch();
// Open a new page
const page = await browser.newPage();
try {
// Navigate to the webpage
await page.goto('https://stonybrook.nutrislice.com/menu/east-side-dining');
// Wait for the page to fully load
await page.waitForNavigation({ waitUntil: 'networkidle0' });
// Scrape all elements with class 'menu-item'
const menuItems = await page.evaluate(() => {
// Use Array.from to convert NodeList to Array
const items = Array.from(document.querySelectorAll('.menu-item'));
// Map over the array to extract text content from each element
return items.map(item => item.textContent.trim());
});
// Output the menu items
console.log('Menu Items:');
console.log(menuItems);
} catch (error) {
console.error('Error:', error);
} finally {
// Close the browser
await browser.close();
}
}
// Call the scraping function
scrapeMenuItems();