-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchEmote.js
59 lines (48 loc) · 1.29 KB
/
fetchEmote.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
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
import puppeteer from "puppeteer";
const arg = process.argv.slice(2);
let emotesFound = false;
(async () => {
const browser = await puppeteer.launch({
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
],
ignoreHTTPSErrors: true,
headless: true,
});
const page = await browser.newPage();
const emote = arg[0];
await page.goto("https://old.7tv.app/emotes?page=1&query=" + emote, {
waitUntil: "networkidle2",
});
try {
await page.waitForSelector(".emote-card-wrapper", {
visible: true,
timeout: 10000,
});
emotesFound = true;
} catch (error) {
console.log("No emotes found");
}
const data = await page.evaluate(() => {
const emoteCards = document.querySelectorAll(
".emote-card-wrapper .emote-card",
);
const result = [];
emoteCards.forEach((card) => {
const link = card.querySelector("a");
const titleBanner = card.querySelector(".title-banner");
if (link && titleBanner) {
const href = link.getAttribute("href");
const title = titleBanner.textContent.trim();
result.push({ href, title });
}
});
return result;
});
if (emotesFound == true) {
console.log(JSON.stringify(data));
}
await browser.close();
})();