forked from k1m190r/evangeler2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawler.js
More file actions
39 lines (32 loc) · 1.44 KB
/
crawler.js
File metadata and controls
39 lines (32 loc) · 1.44 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
38
39
let $table = $("#app main div.relative.overflow-x-auto > table");
let data = [];
let storedData = localStorage.getItem("data");
if (storedData) {
data = JSON.parse(storedData);
}
let index = 0;
let $el = $table;
while (true) {
const brandNode = $el.querySelector("tr:nth-child(" + (index + 1) + ") > td:nth-child(1) > div > div:nth-child(2) > a");
let brand = brandNode?.textContent;
let imageUrl = $el.querySelector("tr:nth-child(" + (index + 1) + ") > td:nth-child(1) > div > div.flex-shrink-0.w-10.h-10 > img")?.getAttribute("src");
const descriptionNode = $el.querySelector("tr:nth-child(" + (index + 1) + ") > td:nth-child(2)");
let description = descriptionNode ? descriptionNode.textContent : '';
let website = $el.querySelector("tr:nth-child(" + (index + 1) + ") > td:nth-child(3) > a")?.textContent;
let keywords = Array.from($el.querySelectorAll("tr:nth-child(" + (index + 1) + ") > td:nth-child(4) > div")).filter(el => el);
keywords = keywords.map(el => el ? el.textContent: '');
keywords = keywords.filter(keyword => keyword !== '');
if (!brand || !imageUrl || !description || !website || !keywords || keywords.includes(null)) {
break;
}
data.push({
brand: brand,
imageUrl: imageUrl,
description: description,
website: website,
keywords: keywords.join(", ")
});
index++;
}
console.log(data);
localStorage.setItem("data", JSON.stringify(data));