12
10

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.

国会会議録検索システム検索用API

Last updated at Posted at 2016-02-13

はじめに

国立国会図書館は明治時代からの国会議事録を全て保存しているそうです。
そして、近年の議事録は家庭のパソコンからでも検索できます。

本題

検索システムのAPIも公開されています。返戻データはXMLです。
国会会議録検索システム検索用APIについて

そんなわけで、とりあえず最小限の例を書いてみたところ。
検索用語の発言を過去1年間分、XMLで取得できるリンクを生成します。

こんなコードでは簡易検索を使った方が便利ですが、この程度で出来るなら偉い人は色々と展開できるんじゃないかと。

HTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
<script src="lib.js"></script>
<title>国会議事録検索</title>
</head>
<body>
<form>
<input type="text" id="WORD" size="30" maxlength="20"/>
<button type="button" id="GO">URI生成</button>
</form>
</body></html>
lib.js
const LIB = {};

LIB.uri = function (word) {
  'use strict';
  const toDb = function(num) {
    num = num.toString();
    if (num.length === 1) {
      num = '0' + num;
    }
    return num;
  };
  const period = (function () {
    const now = new Date();
    const year = now.getFullYear();
    const days = '-' + toDb(now.getMonth() + 1) + '-' + toDb(now.getDate());
    const Dold = (year - 1) + days;
    const Dnow = year + days;
    return 'from=' + Dold + '&' + 'until=' + Dnow;
  }());
  const base = 'http://kokkai.ndl.go.jp/api/1.0/speech?';
  return base + encodeURIComponent('any=' + word + '&' + period);
};

LIB.getXml = function () {
  'use strict';
  const ns = 'http://www.w3.org/1999/xhtml';
  const word = document.getElementById('WORD').value;
  const aElm = document.createElementNS(ns, 'a');
  aElm.setAttribute('href', LIB.uri(word));
  aElm.appendChild(document.createTextNode(word));
  const pElm = document.createElementNS(ns, 'p');
  pElm.appendChild(aElm);
  const bElm = document.getElementsByTagNameNS(ns, 'body').item(0);
  bElm.appendChild(pElm);
};

LIB.addEvent = function () {
  'use strict';
  LIB.button = document.getElementById('GO');
  LIB.button.addEventListener('click', LIB.getXml, false);
  window.removeEventListener('DOMContentLoaded', LIB.addEvent, false);
};

(function () {
  'use strict';
  document.addEventListener('DOMContentLoaded', LIB.addEvent, false);
}());
12
10
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
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?