LoginSignup
1
1

More than 3 years have passed since last update.

ニコニコ動画のページからタイトルetc.を取り出す

Last updated at Posted at 2021-01-15

chrome拡張機能を作るときに必要になったので。

タイトル

title
var row_data = document.getElementById('js-initial-watch-data').getAttribute("data-api-data");
var title = JSON.parse(row_data).video.title;

タグをリストで

tags
var row_data = document.getElementById('js-initial-watch-data').getAttribute("data-api-data");
var tags = JSON.parse(row_data).tags;
for(var i=0; i<tags.length; i++){
  console.log(tags[i].name);
}

あとがき

ニコニコ動画はjs-initial-watch-dataというIDの要素のdata-api-data属性にjson形式で様々なデータがくっついています。
このデータには今回取り出したような動画タイトルやタグのほか、コメントも含まれています。

質問、誤りなどあったらコメントください。

1
1
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
1
1