3
3

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.

Nature OpenSearch APIによる論文タイトルの取得

Last updated at Posted at 2017-12-31

Nature's API

学術雑誌"Nature"は以下のAPIを公開しています。(also see API References)

本稿はOpenSearch APIについての紹介記事です。
余談ですが、natureの更新情報を得るのみでしたらweb feedが与えられているため、こちらを使用するほうが楽かと思います。

The nature.com OpenSearch

OpenSearch APIはweb上でリクエストフォームが与えられており、こちらでIndexを1つ以上選択、またParameterを適当に選択することで、検索することが可能です。

OpenSearch APIページで紹介されているcheatsheetがNot foundなので、OpenSearch APIThe nature.com OpenSearchを見ながらIndexやParameterを設定することとなります。

  • Index

    • クエリ言語CQLやXMLスキーマのPAM (PRISM Aggregator Message)を設定します
    • prism.volume: NatureのVolumeに対応
    • prism.number: 同Number
    • prism.publicationDate: 出版日
      • なぜかデフォルトのメディアタイプ"SRU"ではヒットしませんが、"21 December 2017"のようなnature.comに記載された出版日で検索をかけることが可能です
  • Parameter

    • APIの検索結果の書き出し方式について指定します
    • html上では指定しない場合、デフォルト値が指定される模様です
      • これはメディアタイプを指定しない書き出しでSRUフォーマットであったことから判断しています
  • html sample

    • Volume 552 Number 7685について、jsonで書き出す場合、
      https://www.nature.com/opensearch/request?interface=sru&query=prism.number+%3D+%227685%22+AND+prism.volume+%3D+%22552%22&httpAccept=application%2Fjson で結果を得ることが出来ます。

論文タイトルの取得

あとはAPIの結果を加工するだけです。
Pythonのサンプルを載せておきます。


import requests
import json

def request_nature_api(vol, num):
	url = "https://www.nature.com/opensearch/request?query=prism.number+%3D+%22" + str(num) + "%22+AND+prism.volume+%3D+%22" + str(vol) + "%22&httpAccept=application%2Fjson"
	results = requests.get(url).text
	return(results)

def get_titles(data):
	id_dict = json.loads(data)
	for i in range(0,len(id_dict["feed"]["entry"]) ):
		print(id_dict["feed"]["entry"][i]["title"])


if __name__ == "__main__":
	volume = 552
	number = 7685
	results = request_nature_api(volume, number)
	get_titles(results)

エラーハンドラ等ないぱっと書いたものですので、適宜修正の必要があります。
毎週natureのタイトル等を自動で取得し、Slack等のSNSに流すのであれば、prism.publicationDateを指定して取得した方がいいかもしれません。

追記

PythonでOpenSearch APIを用いるモジュールを高橋さんが開発されました。
https://github.com/takashi-takahashi/nature_open_search

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?