Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

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

はじめに

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

本題

検索システムの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);
}());
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
10
Help us understand the problem. What are the problem?