LoginSignup
24
25

More than 5 years have passed since last update.

Pythonで国立国会図書館サーチAPIを使用

Last updated at Posted at 2016-10-29

使用するAPI

国立国会図書館サーチ外部提供インタフェース(API)

使用するライブラリ

test.py
# -*- coding: utf-8 -*-

from pyndlsearch.client import SRUClient
from pyndlsearch.cql import CQL


if __name__ == '__main__':
    # CQL検索クエリの組み立て
    cql = CQL()
    cql.title = 'Python'
    cql.fromdate = '2000-10-10'
    #print(cql.payload())

    # NDL Searchクライアントの設定
    client = SRUClient(cql)
    client.set_maximum_records(2)
    #print(client)

    # get_response()ではxml形式で取得可能
    #res = client.get_response()
    #print(res.text)

    # SRU
    srres = client.get_srresponse()

    for record in srres.records:
        print(record.recordData.title)
        print(record.recordData.creator)
  • 出力結果
10日でおぼえるPython入門教室
穂苅実紀夫, 寺田学, 中西直樹, 堀田直孝, 永井孝 著
1500円定番ARMマイコン・ボードで試して合点! アプリはスクリプトで柔軟に!マイコン用MicroPythonプログラミング
中村 晋一郎

説明

API仕様書に記載されているCQLという検索クエリを組み立てて検索します.

Responseは構造化されたものを得るget_srresponse()か生のxmlを得るget_response()を使用できます.

searchRetrieveResponse

  • version
  • numberOfRecords
  • nextRecordPosition
  • extraResponseData
    • facets {
      REPOSITORY_NO,
      NDC,
      ISSUED_DATE,
      LIBRARY,
      }
  • records
    • recordSchema
    • recordPacking
    • recordData{
      title,
      creator,
      descriptions,
      publisher,
      language,
      }
    • recordPosition

pyndlsearch

24
25
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
24
25