我需要自动化 PubMed 文章收集。我只找到了通过术语查询下载 PubMed 文章和通过pmid下载 PubMed 文章的示例。(一篇文章)但我正在考虑的是按日期(从到)或全部下载 PubMed ID 的列表,就像在 OAI 中一样。
问问题
856 次
1 回答
3
您可以将BioPython用于此类目的。以下代码片段将为您提供特定日期范围内所有 PubMed 文章的链接。PMC 文章可以直接下载,其他文章提供 DOI,但 PDF 的位置是特定于出版商的,无法预测所有文章的位置。
def article_links(start_date, end_date = '3000'):
"""
start_date, end_date = 'YYYY/MM/DD'
returns a list of PubMedCentral links and a 2nd list of DOI links
"""
from Bio import Entrez
Entrez.email = "Your.Name.Here@example.org"
#get all articles in certain date range, in this case 5 articles which will be published in the future
handle = Entrez.esearch(db="pubmed", term='("%s"[Date - Publication] : "%s"[Date - Publication]) ' %(start_date, end_date))
records = Entrez.read(handle)
#get a list of Pubmed IDs for all articles
idlist = ','.join(records['IdList'])
handle = Entrez.efetch("pubmed", id=idlist, retmode="xml")
records = Entrez.parse(handle)
pmc_articles = []
doi = []
for record in records:
#get all PMC articles
if record.get('MedlineCitation'):
if record['MedlineCitation'].get('OtherID'):
for other_id in record['MedlineCitation']['OtherID']:
if other_id.title().startswith('Pmc'):
pmc_articles.append('http://www.ncbi.nlm.nih.gov/pmc/articles/%s/pdf/' % (other_id.title().upper()))
#get all DOIs
if record.get('PubmedData'):
if record['PubmedData'].get('ArticleIdList'):
for other_id in record['PubmedData']['ArticleIdList']:
if 'doi' in other_id.attributes.values():
doi.append('http://dx.doi.org/' + other_id.title())
return pmc_articles, doi
if __name__ == '__main__':
print (article_links('2016/12/20'))
于 2016-06-16T13:05:20.837 回答