7

我想下载所有已发布的数据摘要。有谁知道我如何可以轻松下载所有已发表的文章摘要?

我得到了数据的来源:ftp: //ftp.ncbi.nlm.nih.gov/pub/pmc/af/12/

无论如何要下载所有这些tar文件..

提前致谢。

4

2 回答 2

3

有一个名为rentrezhttps://ropensci.org/packages/的包。看一下这个。您可以通过特定关键字或 PMID 等检索摘要。希望对您有所帮助。

更新:您可以通过使用以下代码传递您的 IDS 列表来下载所有摘要。

    library(rentrez)
    library(xml)

your.ids <- c("26386083","26273372","26066373","25837167","25466451","25013473")
# rentrez function to get the data from pubmed db
fetch.pubmed <- entrez_fetch(db = "pubmed", id = your.ids,
                      rettype = "xml", parsed = T)
# Extract the Abstracts for the respective IDS.  
abstracts = xpathApply(fetch.pubmed, '//PubmedArticle//Article', function(x)
                               xmlValue(xmlChildren(x)$Abstract))
# Change the abstract names with the IDS.
names(abstracts) <- your.ids
abstracts
col.abstracts <- do.call(rbind.data.frame,abstracts)
dim(col.abstracts)
write.csv(col.abstracts, file = "test.csv")
于 2015-11-04T14:12:49.397 回答
2

我很欣赏这是一个有点老的问题。

如果您希望使用 python 获取所有已发布的条目,我不久前编写了以下脚本:

import requests
import json

search_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&mindate=1800/01/01&maxdate=2016/12/31&usehistory=y&retmode=json"
search_r = requests.post(search_url)
search_data = search_r.json()
webenv = search_data["esearchresult"]['webenv']
total_records = int(search_data["esearchresult"]['count'])
fetch_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmax=9999&query_key=1&webenv="+webenv

for i in range(0, total_records, 10000):
    this_fetch = fetch_url+"&retstart="+str(i)
    print("Getting this URL: "+this_fetch)
    fetch_r = requests.post(this_fetch)
    f = open('pubmed_batch_'+str(i)+'_to_'+str(i+9999)+".json", 'w')
    f.write(fetch_r.text)
    f.close()

print("Number of records found :"+str(total_records))

它首先在 2 个日期之间发出 entrez/eutils 搜索请求,这可以保证捕获所有 pubmed。然后从该响应中检索“webenv”(保存搜索历史)和 total_records。使用 webenv 功能无需将单独的记录 ID 交给 efetch 调用。

获取记录 (efetch) 只能以 10000 条为单位进行,for 循环处理 9,999 条记录的批量抓取并将它们保存在带标签的文件中,直到检索到所有记录。

请注意,请求可能会失败(非 200 个 http 响应、错误),在更强大的解决方案中,您应该将每个 requests.post() 包装在 try/except 中。在转储/使用数据到文件之前,您应该确保 http 响应具有 200 状态。

于 2016-08-10T14:03:30.210 回答