我正在尝试使用Scopus API来检索由scopus分配给作者的唯一作者标识号。在某些情况下,名称将产生多个作者ID。我的麻烦在于阅读json格式,以便我可以解析出dc:identifier'
这是我的代码:
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)"
}
我需要做的就是解析这个问题,以便获得“dc:identifier'拉起来了。在这种情况下,有3.
理想情况下,我想将其放入我所拥有的表格中 AUTHLASTNAME / AUTHFIRST / DCIDENTIFER(在专栏中)
任何建议表示赞赏。
答案 0 :(得分: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)
这将获得第1部分的信息:
UIRefreshControl
您可以使用类似的内容来处理每个print( [e["dc:identifier"] for e in results['search-results']['entry']] )
的其他信息。
至于第2部分:python没有表格。