如何使用Elsevier文章检索API获取论文全文

2024-04-24 13:25:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用Elsevier文章检索API(https://dev.elsevier.com/documentation/FullTextRetrievalAPI.wadl)获取论文全文

我使用httpx获取论文信息,但它只包含一些信息。我的代码如下:

import httpx
import time


def scopus_paper_date(paper_doi,apikey):
    apikey=apikey
    headers={
        "X-ELS-APIKey":apikey,
        "Accept":'text/xml'
         }

    timeout = httpx.Timeout(10.0, connect=60.0)
    client = httpx.Client(timeout=timeout,headers=headers)
    query="&view=FULL"
    url=f"https://api.elsevier.com/content/article/doi/" + paper_doi
    r=client.get(url)
    print(r)
    return r.text

y = scopus_paper_date('10.1016/j.solmat.2021.111326',myapikey)
y

结果如下:

<full-text-retrieval-response xmlns="http://www.elsevier.com/xml/svapi/article/dtd" xmlns:bk="http://www.elsevier.com/xml/bk/dtd" xmlns:cals="http://www.elsevier.com/xml/common/cals/dtd" xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:ja="http://www.elsevier.com/xml/ja/dtd" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:sa="http://www.elsevier.com/xml/common/struct-aff/dtd" xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd" xmlns:tb="http://www.elsevier.com/xml/common/table/dtd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xocs="http://www.elsevier.com/xml/xocs/dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:prism="http://prismstandard.org/namespaces/basic/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><coredata><prism:url>https://api.elsevier.com/content/article/pii/S0927024821003688</prism:url>....

我怎样才能得到论文的全部数据,非常感谢


Tags: httpsorgcomhttpurlwwwdoixml
1条回答
网友
1楼 · 发布于 2024-04-24 13:25:30

这取决于你想下载的论文

我对你发布的函数做了一些修改。现在它得到的响应是JSON而不是XML(这只是我个人的偏好,您可以使用您喜欢的格式)

import httpx
import time

def scopus_paper_date(paper_doi,apikey):
    apikey=apikey
    headers={
        "X-ELS-APIKey":apikey,
        "Accept":'application/json'
         }
    timeout = httpx.Timeout(10.0, connect=60.0)
    client = httpx.Client(timeout=timeout,headers=headers)
    query="&view=FULL"
    url=f"https://api.elsevier.com/content/article/doi/"+paper_doi
    r=client.get(url)
    print(r)
    return r

现在,您可以检索所需的文档,并且必须对其进行解析:

# Get document
y = scopus_paper_date('10.1016/j.solmat.2021.111326',my_api_key)
# Parse document
import json
json_acceptable_string = y.text
d = json.loads(json_acceptable_string)
# Print document
print(d['full-text-retrieval-response']['coredata']['dc:description'])

结果将显示文件的dc:description,即摘要:

The production of molecular hydrogen by photoelectrochemical dissociation (PEC) of water is a promising technique, which allows ... The width of the forbidden bands and the position of the valence and conduction bands of the different materials were determined by Mott - Schottky type measurements.

对于这篇你能得到的全部文档,没有更多的选项了。 但是,如果您尝试获取其他文档,例如:

# Get document
y = scopus_paper_date('10.1016/j.nicl.2021.102600',my_api_key)
# Parse document
import json
json_acceptable_string = y.text
d = json.loads(json_acceptable_string)

然后可以打印full-text-retrieval-responseoriginalText

# Print document
print(d['full-text-retrieval-response']['originalText'])

您会注意到,这是一个非常长的字符串,包含大量文本,可能比您想要的更多,例如,它还包含所有引用

正如我在开始时所说,你能得到的信息取决于一张纸。但是,完整数据将始终包含在代码中定义的y变量中

相关问题 更多 >