Created
February 14, 2025 07:03
-
-
Save nillpo/bb0a7c0fdf5d7e0f6b2b9b1a1edacf41 to your computer and use it in GitHub Desktop.
サリチル酸さんの週報リスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { DOMParser } from "jsr:@b-fuze/deno-dom"; | |
| const years = ["2021", "2022", "2023", "2024", "2025"]; | |
| const postedDate: { post_date: string; title: string; url: string }[] = []; | |
| for (const year of years) { | |
| let page = 1; | |
| while (true) { | |
| const res = await fetch( | |
| `https://salicylic-weekly.hatenablog.jp/archive/${year}?page=${page}`, | |
| ); | |
| const doc = (new DOMParser()).parseFromString( | |
| await res.text(), | |
| "text/html", | |
| ); | |
| const sectons = doc.querySelectorAll( | |
| "#main-inner div.archive-entries section.archive-entry", | |
| ); | |
| for (const section of Array.from(sectons)) { | |
| const date = section.querySelector(".date.archive-date")?.textContent | |
| .trim()!; | |
| const title = section.querySelector("h1.entry-title")?.textContent | |
| .trim()!; | |
| const url = section.querySelector("h1.entry-title>a")?.getAttribute( | |
| "href", | |
| )!; | |
| postedDate.push({ post_date: date, title, url }); | |
| } | |
| if (doc.querySelector("span.pager-next")) { | |
| page++; | |
| } else { | |
| break; | |
| } | |
| } | |
| } | |
| postedDate.sort((a, b) => a.post_date > b.post_date ? 1 : -1); | |
| console.log(JSON.stringify(postedDate)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment