簡単なメモ
海外の有名掲示板「reddit」のコメントを、json形式で取得して、後続のツールに流したい
例えばこのスレッドの以下のような人間が読みやすいコメントを

json形式で取得して、後続のツールに落とし込みたい場合は、
そのコメントのURL
https://www.reddit.com/r/baseball/comments/(thread_id)/(thread_title)/
の末尾に、.json
を付与してやるだけ
https://www.reddit.com/r/baseball/comments/(thread_id)/(thread_title)/.json
これをブラウザに入力するとか、LinuxのCurl
コマンドで叩いてやれば、.json
を取得できる。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ curl https://www.reddit.com/r/baseball/comments/1dk10qf/shohei_ohtani_takes_a_lead_off_first_base/.json | jq . % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 329k 100 329k 0 0 187k 0 0:00:01 0:00:01 --:--:-- 187k [ { "kind": "Listing", "data": { "after": null, "dist": 1, "modhash": "", "geo_filter": "", ~~~ |
ちなみに、コメント自体は.[].data.children[].data
…(A) の.body
のパスにあるようで、そこからコメントへの返信は (A) から.replies.data.children[].data.body
に入ってる模様

1 2 3 4 5 |
$ curl https://www.reddit.com/r/baseball/comments/1dk10qf/shohei_ohtani_takes_a_lead_off_first_base/.json | jq '.[].data.children[].data.body | select(. == "Why the fuck was that so cinematic")' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 329k 100 329k 0 0 151k 0 0:00:02 0:00:02 --:--:-- 151k "Why the fuck was that so cinematic" |
1 2 3 4 5 6 7 8 9 10 |
$ curl https://www.reddit.com/r/baseball/comments/1dk10qf/shohei_ohtani_takes_a_lead_off_first_base/.json | jq '.[].data.children[].data | select(.body == "Why the fuck was that so cinematic") | .replies.data.children[].data.body' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 329k 100 329k 0 0 221k 0 0:00:01 0:00:01 --:--:-- 221k "Shohei was ready to wreck some shit" "The aspect ratio!" "Shohei is a charm and cinematic type of guy" "Parallax of the lens gives the players visual intimacy + the subtle shift from one players face to another obscures the focus reshifting onto Ohtani because both their faces are never fully in frame. This is a beautiful bit of camera wizardry, only way I’d upgrade it is get a split diopter with a sort of Altmanesque twist to really heighten the drama." "r/PraiseTheCameraMan" ~~~ |
以上