-3

我正在尝试使用 api 和 python 从 scopus 获取数据。我使用 python 模块请求进行查询。查询的响应为我提供了一个 json,其值如下所示。

{“搜索结果”:{“opensearch:totalResults”:“1186741”,“opensearch:startIndex”:“0”,“opensearch:itemsPerPage”:“25”,“opensearch:Query”:{“@role”: “请求”,“@searchTerms”:“所有(机器学习)”,“@startPage”:“0”},“链接”:[{“@_fa”:“true”,“@ref”:“self” , "@href": "api 查询", "@type": "application/json" }, { "@_fa": "true", "@ref": "first",“@href”:“api 查询”,“@type”:“application/json”},{ “@_fa”:“true”,“@ref”:“下一个”,“@href”:“api 查询” , "@type": "application/json" }, { "@_fa": "true", "@ref": "last", "@href": "api 查询", "@type": "application/ json" } ], "entry": [ { "@_fa": "true", "link": [ { "@_fa": "真”,“@ref”:“自我”,“@href”:“https://api.elsevier.com/content/abstract/scopus_id/85081889595 " }, { "@_fa": "true", "@ref": "作者-隶属关系", "@href": " https:// /api.elsevier.com/content/abstract/scopus_id/85081889595?field=author,affiliation " }, { "@_fa": "true", "@ref": "scopus", "@href": " https: //www.scopus.com/inward/record.uri?partnerID=HzOxMe3b&scp=85081889595&origin=inward " }, { "@_fa":“真”,“@ref”:“scopus-citedby”,“@href”:“https://www.scopus.com/inward/citedby.uri?partnerID=HzOxMe3b&scp=85081889595&origin=inward " } ], "prism:url": " https://api.elsevier.com/content/abstract/scopus_id/ 85081889595", "dc:identifier": "SCOPUS_ID:85081889595", "eid": "2-s2.0-85081889595", "dc:title": "通过文本和音频挖掘识别 PTSD 简短折衷心理治疗中的热点", “dc:creator”:“Wiegersma S.”,“prism:publicationName”:“欧洲精神创伤学杂志”,“prism:issn”:“20008198”,“prism:eIssn”:“20008066”,“prism:volume” :“11”,“棱镜:issueIdentifier”:“1”,“棱镜:pageRange”:空,“棱镜:coverDate”:“2020-12-31”,“棱镜:coverDisplayDate”:“2020 年 12 月 31 日”,“prism:doi”:“10.1080/20008198.2020.1726672”,“citedby-count”:“0”,“affiliation”:[ { “@_fa”:“true”,“affilname ": "University of Twente", "affiliation-city": "Enschede", "affiliation-country": "Netherlands" } ], "prism:aggregationType": "Journal", "subtype": "ar", "subtypeDescription ": "文章", "文章编号": "1726672",“源ID”:“21100394256”,“openaccess”:“1”,“openaccessFlag”:真},

但是,响应是嵌套的 json,我无法访问它的内部元素,例如键 dc:creator、citedby-count 等。

任何人都可以帮助我了解如何访问它的所有部分,例如作者姓名、引用者、隶属关系等。我想将此结果存储为 csv,以便进一步操作。

直接申请

df = pandas.read_json(文件名)

没有产生正确的结果格式:我得到一个这样的表。

entry [{'@_fa': 'true', 'link': [{'@_fa': 'true', '@... link [{'@_fa': 'true', '@ref': 'self', '@href': 'ht... opensearch:Query {'@role': 'request', '@searchTerms': 'all(mach... opensearch:itemsPerPage 25 opensearch:startIndex 0 opensearch:totalResults 1186741

我也尝试过通过嵌套字典访问以列出字典方法,但在某些时候,我被卡住了。

with open('data.json', encoding='utf-8') as access:
      read_file = json.load(access)

…</p>

type(read_file)

这是一本字典,所以我按照字典的语法进一步访问,它在某个点转换为列表并再次转换为字典。

我的主要要求是 - **如何创建一个带有列标题的 csv 文件,这些标题将是条目标签内的标签,如 dc:identifier、dc:title、dc:creator、citedby-count 等,以及其中的值 ** 在此处输入代码

4

1 回答 1

0
import json
dict_data = json.loads(response)
print(dict_data['key'])

你是这个意思吗 ?

于 2020-05-07T08:03:44.017 回答