-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
28 lines (25 loc) · 852 Bytes
/
server.js
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
const { default: puppeteer } = require("puppeteer");
fetchConcerts("Mass of the fermenting dregs")
async function fetchConcerts(artist) {
const query = artist.replaceAll(" ", "%20")
console.log(query);
const url = `https://www.ticketmaster.com/search?q=${query}`;
console.log(url);
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(url, {
waitUntil: "domcontentloaded",
});
const dataTestId = "eventList";
let concerts;
try {
concerts = await page.$eval(`[data-testid="${dataTestId}"]`, (element) => {
console.log("element ", element.innerHTML);
return element.innerHTML;
});
} catch (err) {
console.log("No events for", artist);
concerts = "";
}
return concerts;
}