Created
August 5, 2021 04:05
-
-
Save nokazn/5bd01c9715d839f3184088b15642f6a3 to your computer and use it in GitHub Desktop.
.har ファイルから URL を取り出して出力する
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 * as fs from 'fs'; | |
| import { z } from 'zod'; | |
| const SCHEMA = z.object({ | |
| log: z.object({ | |
| entries: z.array( | |
| z.object({ | |
| request: z.object({ | |
| url: z.string(), | |
| }), | |
| }), | |
| ), | |
| }), | |
| }); | |
| const main = () => { | |
| const harFilePath = process.argv[2]; | |
| if (typeof harFilePath !== 'string') { | |
| throw new Error('.har ファイルのパスを指定してください。'); | |
| } | |
| const file = fs.readFileSync(harFilePath).toString(); | |
| const json = JSON.parse(file); | |
| const res = SCHEMA.parse(json); | |
| const urls = res.log.entries.map((e) => e.request.url).join('\n'); | |
| process.stdout.write(urls); | |
| }; | |
| main(); |
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
| { | |
| "devDependencies": { | |
| "@types/node": "^16.4.12", | |
| "ts-node": "^10.1.0", | |
| "typescript": "^4.3.5" | |
| }, | |
| "dependencies": { | |
| "zod": "^3.7.1" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment