2016-12-06 2 views
-1

Scopus APIを使用して、scopusによって著者に割り当てられた一意の著者ID番号を取得しようとしています。場合によっては、名前によって複数の著者IDが生成されます。私が解析できるように、私のトラブルは、JSON形式の読み込みには「DCを:識別子」ここ多くの値に辞書を解析し、Pythonでテーブルを作成する

は私のコードです:

import requests 
    import json 

    url = "http://api.elsevier.com/content/search/author" 

    querystring = {"apiKey":"xxxxxxxxxxxxx","query":["AUTHLASTNAME(Volaire)","AUTHFIRST(F)"]} 

    headers = { 
    'cache-control': "no-cache", 
    'postman-token': "5c0df5ad-2645-8e88-0f8a-10795757b4ec" 
    } 

    response = requests.request("GET", url, headers=headers, params=querystring) 

    results = response.json() 

私は、次のような出力を得る:

{ 
    "search-results": { 
    "opensearch:totalResults": "3", 
    "opensearch:startIndex": "0", 
    "opensearch:itemsPerPage": "3", 
    "opensearch:Query": { 
     "@role": "request", 
     "@searchTerms": "AUTHLASTNAME(Volaire)", 
     "@startPage": "0" 
    }, 
    "link": [ 
     { 
     "@_fa": "true", 
     "@href": "http://api.elsevier.com/content/search/author?start=0&count=25&query=AUTHLASTNAME%28Volaire%29&apiKey=4275854a6db51fb373ef69fb1337ccf9", 
     "@ref": "self", 
     "@type": "application/json" 
     }, 
     { 
     "@_fa": "true", 
     "@href": "http://api.elsevier.com/content/search/author?start=0&count=25&query=AUTHLASTNAME%28Volaire%29&apiKey=4275854a6db51fb373ef69fb1337ccf9", 
     "@ref": "first", 
     "@type": "application/json" 
     } 
    ], 
    "entry": [ 
     { 
     "@_fa": "true", 
     "link": [ 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/author/author_id/55910750900", 
      "@ref": "self" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/search/author?query=au-id%2855910750900%29", 
      "@ref": "search" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/author/citedby.uri?partnerID=HzOxMe3b&citedAuthorId=55910750900&origin=inward", 
      "@ref": "scopus-citedby" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/authid/detail.uri?partnerID=HzOxMe3b&authorId=55910750900&origin=inward", 
      "@ref": "scopus-author" 
      } 
     ], 
     "prism:url": "http://api.elsevier.com/content/author/author_id/55910750900", 
     "dc:identifier": "AUTHOR_ID:55910750900", 
     "eid": "9-s2.0-55910750900", 
     "preferred-name": { 
      "surname": "Volaire", 
      "given-name": "Florence A.", 
      "initials": "F.A." 
     }, 
     "name-variant": [ 
      { 
      "@_fa": "true", 
      "surname": "Volaire", 
      "given-name": "F.", 
      "initials": "F." 
      }, 
      { 
      "@_fa": "true", 
      "surname": "Volaire", 
      "given-name": "Florence", 
      "initials": "F." 
      } 
     ], 
     "document-count": "41", 
     "subject-area": [ 
      { 
      "@abbrev": "ENVI", 
      "@frequency": "7", 
      "$": "Environmental Science (all)" 
      }, 
      { 
      "@abbrev": "AGRI", 
      "@frequency": "50", 
      "$": "Agricultural and Biological Sciences (all)" 
      }, 
      { 
      "@abbrev": "ENGI", 
      "@frequency": "4", 
      "$": "Engineering (all)" 
      } 
     ], 
     "affiliation-current": { 
      "affiliation-url": "http://api.elsevier.com/content/affiliation/affiliation_id/60020315", 
      "affiliation-id": "60020315", 
      "affiliation-name": "INRA Institut National de La Recherche Agronomique", 
      "affiliation-city": "Paris", 
      "affiliation-country": "France" 
     } 
     }, 
     { 
     "@_fa": "true", 
     "link": [ 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/author/author_id/6603570012", 
      "@ref": "self" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/search/author?query=au-id%286603570012%29", 
      "@ref": "search" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/author/citedby.uri?partnerID=HzOxMe3b&citedAuthorId=6603570012&origin=inward", 
      "@ref": "scopus-citedby" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/authid/detail.uri?partnerID=HzOxMe3b&authorId=6603570012&origin=inward", 
      "@ref": "scopus-author" 
      } 
     ], 
     "prism:url": "http://api.elsevier.com/content/author/author_id/6603570012", 
     "dc:identifier": "AUTHOR_ID:6603570012", 
     "eid": "9-s2.0-6603570012", 
     "preferred-name": { 
      "surname": "Volaire", 
      "given-name": "Florence", 
      "initials": "F." 
     }, 
     "name-variant": [ 
      { 
      "@_fa": "true", 
      "surname": "Volaire", 
      "given-name": "F.", 
      "initials": "F." 
      } 
     ], 
     "document-count": "8", 
     "subject-area": [ 
      { 
      "@abbrev": "AGRI", 
      "@frequency": "13", 
      "$": "Agricultural and Biological Sciences (all)" 
      }, 
      { 
      "@abbrev": "BIOC", 
      "@frequency": "1", 
      "$": "Biochemistry, Genetics and Molecular Biology (all)" 
      } 
     ], 
     "affiliation-current": { 
      "affiliation-url": "http://api.elsevier.com/content/affiliation/affiliation_id/60020315", 
      "affiliation-id": "60020315", 
      "affiliation-name": "INRA Institut National de La Recherche Agronomique", 
      "affiliation-city": "Paris", 
      "affiliation-country": "France" 
     } 
     }, 
     { 
     "@_fa": "true", 
     "link": [ 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/author/author_id/24571987100", 
      "@ref": "self" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "http://api.elsevier.com/content/search/author?query=au-id%2824571987100%29", 
      "@ref": "search" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/author/citedby.uri?partnerID=HzOxMe3b&citedAuthorId=24571987100&origin=inward", 
      "@ref": "scopus-citedby" 
      }, 
      { 
      "@_fa": "true", 
      "@href": "https://www.scopus.com/authid/detail.uri?partnerID=HzOxMe3b&authorId=24571987100&origin=inward", 
      "@ref": "scopus-author" 
      } 
     ], 
     "prism:url": "http://api.elsevier.com/content/author/author_id/24571987100", 
     "dc:identifier": "AUTHOR_ID:24571987100", 
     "eid": "9-s2.0-24571987100", 
     "preferred-name": { 
      "surname": "Volaire", 
      "given-name": "M.", 
      "initials": "M." 
     }, 
     "name-variant": [ 
      { 
      "@_fa": "true", 
      "surname": "Volaire", 
      "given-name": null, 
      "initials": "M." 
      } 
     ], 
     "document-count": "1", 
     "subject-area": [ 
      { 
      "@abbrev": "CHEM", 
      "@frequency": "2", 
      "$": "Chemistry (all)" 
      }, 
      { 
      "@abbrev": "BIOC", 
      "@frequency": "1", 
      "$": "Biochemistry, Genetics and Molecular Biology (all)" 
      }, 
      { 
      "@abbrev": "ENVI", 
      "@frequency": "1", 
      "$": "Environmental Science (all)" 
      } 
  1. 私がする必要があるのは、これを解析して、「dc:identifier」が取得されるようにすることです。この例では3

  2. があります理想的には私は私が(列の) AUTHLASTNAME/AUTHFIRST/DCIDENTIFER

に感謝何かアドバイスを持っているテーブルにこれを入れたいと思います。

+0

投稿されたコードは質問とは関係ありません(作成したデータの処理について)。これは正しいです? –

+0

@ScottHunter:これは正しいですが、json出力にどのように到達したかを教えてくれます。 –

+0

データの入手方法は関係ありません。投稿した出力が不完全です。 –

答えて

0

にそれをチェックトリプルませんでした:

print([e["dc:identifier"] for e in results['search-results']['entry']]) 

あなたはそれぞれentryからの他の情報については、同様のものを使用することができます。

パート2の場合:pythonにはテーブルがありません。

0

多分このようなものでしょうか? ここにあなたが何を持っているのですか?

print(results['search-results']['link']['entry']['dc:identifier']) 

これを試してください。あなたが望む値がjsonのリストの中のオブジェクトの内側にあるので、これはうまくいくはずです。

some_dict = [ 
    { 
     "dc:identifiers": r['dc:identifier'], 
     "AUTHLASTNAME": r['preferred-name']['surname'], 
     "AUTHFIRST": r['preferred-name']['given-name'], 
    } for r in results['search-results']['entry'] 
] 

明らかに、あなたのjsonはその形式にとどまっていると仮定しています。 結果を置くことも確認してください['search-results'] ['entry']実際には正しいです。私は、これはパート1のための情報を取得します

+0

ありがとうございますが、私はこれを得ています: "SyntaxError:予期しない構文解析中のEOF" –

+0

リスト内のオブジェクトが多すぎるため、[検索結果] [エントリ]が混乱している部分だと思います... –

関連する問題