-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathinit-data.ts
More file actions
27 lines (24 loc) · 792 Bytes
/
Copy pathinit-data.ts
File metadata and controls
27 lines (24 loc) · 792 Bytes
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
import { load } from "cheerio"
import fs from "fs"
// 2004 to 2025
const years = Array.from({ length: 2025 - 2004 + 1 }, (_, i) => 2004 + i)
type Item = {
title: string
score: number
}
const result: Record<string, Item[]> = {}
for (const year of years) {
console.log(`正在获取 ${year} 年的数据`)
const url = `https://bgm.tv/anime/browser/tv/airtime/${year}?sort=trends`
const response = await fetch(url)
const html = await response.text()
const $ = load(html)
const items: Item[] = []
$(".item").each((_, el) => {
const title = $(el).find("h3 .l").text().trim()
const score = Number($(el).find(".rateInfo .fade").text().trim())
items.push({ title, score })
})
result[year] = items
}
fs.writeFileSync("anime.json", JSON.stringify(result, null, 2))