This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (47 loc) · 1.66 KB
/
index.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
import puppeteer from 'puppeteer'
import fs from 'fs'
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
})
try {
const page = await browser.newPage()
await page.goto('https://app.optimism.io/retropgf-discovery')
await page.waitForSelector('._primaryButton_7jap0_6')
while (true) {
try {
await page.$eval('._primaryButton_7jap0_6', (button) => button.click())
await page.waitForSelector('._primaryButton_7jap0_6', { timeout: 10000 })
} catch (error) {
break
}
}
page.waitForTimeout(500000)
const cards = await page.$$('._container_1dvyk_1')
for (const List of cards) {
const name = await List.$eval('h3', (h3) => h3.innerText)
const description = await List.$eval('p', (p) => p.innerText)
const category = await List.$eval('button>span', (span) => span.innerText)
// const cleanName = name.replace(/[^a-z0-9]/gi, '_').toLowerCase()
const cleanName = name
fs.mkdirSync(`out/${cleanName}`, { recursive: true })
fs.writeFileSync(
`out/${cleanName}/info.json`,
JSON.stringify({ name, description, category })
)
const icon64 = await List.$eval('._logo_1dvyk_63', (img) => img.src)
const banner64 = await List.$eval(
'._banner_1dvyk_15 > img',
(img) => img.src
)
const icon = Buffer.from(icon64.slice(22), 'base64')
const banner = Buffer.from(banner64.slice(22), 'base64')
fs.writeFileSync(`out/${cleanName}/icon.jpg`, icon, 'binary')
fs.writeFileSync(`out/${cleanName}/banner.jpg`, banner, 'binary')
}
} catch (error) {
console.error('An error occurred:' + error)
} finally {
console.log('Done Scraping')
await browser.close()
}