* 問題一覧を取得 * @param contest_id * @throws Error
(contest_id: string)
| 141 | * @throws Error |
| 142 | */ |
| 143 | async tasks(contest_id: string): Promise<Array<Task>> { |
| 144 | // コンテストが見つからない場合エラーとなるがハンドルせず外に投げる |
| 145 | const response = await this.session.get(AtCoder.getTaskURL(contest_id)); |
| 146 | |
| 147 | const {JSDOM} = await import("jsdom"); |
| 148 | const {document} = new JSDOM(response.data).window; |
| 149 | // very very ad-hoc and not type-safe section |
| 150 | const tbody = document.querySelector("#main-div .row table>tbody"); |
| 151 | if (tbody === null) return []; |
| 152 | const tasks: Array<Task> = []; |
| 153 | for (const tr of tbody.querySelectorAll("tr")) { |
| 154 | // tr>td>a |
| 155 | const id: string = tr.children[0].children[0].getAttribute("href")!.split("/").pop()!; |
| 156 | const label: string = (tr.children[0].children[0] as HTMLAnchorElement).text; |
| 157 | const title: string = (tr.children[1].children[0] as HTMLAnchorElement).text; |
| 158 | const url: string = `${AtCoder.base_url}${tr.children[0].children[0].getAttribute("href")!.substring(1)}`; |
| 159 | tasks.push({id, label, title, url}); |
| 160 | } |
| 161 | return tasks; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * 単一の問題を取得 |