0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ニコニコ動画の情報をブラウザからJSONで取得してコメント部分をPythonで抜き出す

Posted at

はじめに

多少手作業があるが、ニコニコ動画のコメントをざっくりと抜出すのにお手軽かなと。

ブラウザの開発者ツールからレスポンスデータを抜き取る

Chromeです。Windowsだと F12 で開発者ツールの画面を表示。
[Network]のタブを表示して、コメントを取得した動画をリロード。
たぶん、api.json/のレスポンスデータがそれだが、適当なコメントの文字列で検索してもいい。
見つかったら、[Response]のタブでJSON文字列をコピーするか、api.json/を右クリックして[Copy] > [Copy response]をクリックする。

JSON文字列からコメント部分をPythonで抜き取る

import io
import json

with open('niconico.txt', 'r') as f:
	for x in  json.load(f):
		if 'chat' in x:
			y = x['chat']
			print ('%s\t%s' % (y['no'], y['content']))

とりあえずファイル名は固定にして、標準出力へ出力。
出力内容はコメントの番号とコメントのみで、タブで区切っている。
コメント時の動画の位置やコメントした日時が欲しい場合一工夫必要。
自動化するとなったら詳しい情報を記載してくれているすばらしい記事があるのでそちらを参照。

参考にした記事など

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?