darkvibe314 commited on
Commit
4a1685f
·
verified ·
1 Parent(s): 12b2820

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +88 -0
app.js ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const puppeteer = require('puppeteer-extra');
3
+ const StealthPlugin = require('puppeteer-extra-plugin-stealth');
4
+ const fs = require('fs');
5
+
6
+ puppeteer.use(StealthPlugin());
7
+
8
+ const app = express();
9
+ const PORT = 7860;
10
+ let STATUS = "Booting up...";
11
+ let TOTAL_FOUND = 0;
12
+
13
+ // This makes a mini-website so you can track the progress on your phone!
14
+ app.get('/', (req, res) => {
15
+ let html = `<h1>Shoob Database Builder</h1>
16
+ <p><b>Status:</b> ${STATUS}</p>
17
+ <p><b>Total IDs Sniped:</b> ${TOTAL_FOUND}</p>`;
18
+
19
+ if (fs.existsSync('all_35k_ids.json')) {
20
+ html += `<br><br><a href="/download" style="padding:10px 20px; background:green; color:white; text-decoration:none; border-radius:5px;">⬇️ DOWNLOAD JSON</a>`;
21
+ }
22
+ res.send(html);
23
+ });
24
+
25
+ app.get('/download', (req, res) => {
26
+ res.download(__dirname + '/all_35k_ids.json');
27
+ });
28
+
29
+ app.listen(PORT, () => {
30
+ console.log(`Server running on port ${PORT}`);
31
+ startScraping(); // Start the background task!
32
+ });
33
+
34
+ async function startScraping() {
35
+ STATUS = "Scraping Gallery...";
36
+ const browser = await puppeteer.launch({
37
+ headless: "new",
38
+ executablePath: '/usr/bin/google-chrome-stable',
39
+ args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage', '--disable-gpu']
40
+ });
41
+
42
+ let allIds = new Set();
43
+ const TOTAL_PAGES = 2355;
44
+ const CONCURRENCY = 20; // 🔥 20 Tabs at once using HF Servers!
45
+
46
+ for (let i = 1; i <= TOTAL_PAGES; i += CONCURRENCY) {
47
+ let promises = [];
48
+
49
+ for (let j = 0; j < CONCURRENCY && (i + j) <= TOTAL_PAGES; j++) {
50
+ let pageNum = i + j;
51
+ promises.push((async () => {
52
+ const page = await browser.newPage();
53
+ await page.setRequestInterception(true);
54
+ page.on('request', (req) => {
55
+ if (['image', 'media'].includes(req.resourceType())) req.abort();
56
+ else req.continue();
57
+ });
58
+
59
+ try {
60
+ await page.goto(`https://shoob.gg/cards?page=${pageNum}`, { waitUntil: 'domcontentloaded', timeout: 30000 });
61
+ await page.waitForFunction(() => document.querySelectorAll('a[href*="/cards/info/"]').length > 0, { timeout: 15000 });
62
+
63
+ const ids = await page.evaluate(() => {
64
+ return Array.from(document.querySelectorAll('a[href*="/cards/info/"]'))
65
+ .map(el => el.href.split('/').pop())
66
+ .filter(id => id && id.length === 24);
67
+ });
68
+
69
+ ids.forEach(id => allIds.add(id));
70
+ } catch(e) {
71
+ console.log(`Skipped page ${pageNum}`);
72
+ } finally {
73
+ await page.close();
74
+ }
75
+ })());
76
+ }
77
+
78
+ await Promise.all(promises);
79
+ TOTAL_FOUND = allIds.size;
80
+ STATUS = `Scraping... Just finished Page ${Math.min(i + CONCURRENCY - 1, TOTAL_PAGES)}`;
81
+
82
+ // Save progress
83
+ fs.writeFileSync('all_35k_ids.json', JSON.stringify(Array.from(allIds), null, 2));
84
+ }
85
+
86
+ STATUS = "✅ FINISHED! CLICK DOWNLOAD BELOW!";
87
+ await browser.close();
88
+ }