Biopython Entrez查询PMC文章ID返回空列表的问题求助
问题:PMC数据库搜索返回空列表的排查
我用下面的代码下载标题/摘要含指定关键词、且在指定日期范围内的PubMed Central(PMC)文章ID。选database="pubmed"时代码正常运行,能拿到4个PubMed ID:['36902449', '36880658', '36583446', '35239250'],手动查发现第一个ID对应的文章也在PMC库中(对应PMC ID为10003631),但切换到database="pmc"时却返回空列表,求指出忽略的问题。
import os import datetime from Bio import Entrez # Set the email address to identify yourself to NCBI Entrez.email = "example@gmail.com" # Set the date range for the search start_date = datetime.datetime(2023, 3, 1) end_date = datetime.datetime(2023, 3, 22) # Format the dates as strings in the correct format start_date_str = start_date.strftime("%Y/%m/%d") end_date_str = end_date.strftime("%Y/%m/%d") # Build the search query with the date range keyword = "dosage compensation" # database = "pubmed" database = "pmc" # Use esearch to fetch the list of matching article IDs if database == "pubmed": search_term = f'("{start_date_str}"[Date - Publication] : "{end_date_str}"[Date - Publication]) AND {keyword}[Title/Abstract]' handle = Entrez.esearch(db=database, term=search_term, retmax=100, api_key = os.environ['ENTREZ_API_KEY']) elif database == "pmc": search_term = f'("{start_date_str}"[Publication Date] : "{end_date_str}"[Publication Date]) AND {keyword}[Title/Abstract] AND open_access[filter]' handle = Entrez.esearch(db=database, term=search_term, retmax=1000, api_key = os.environ['ENTREZ_API_KEY']) record = Entrez.read(handle) id_list = record['IdList'] handle.close() # Print the number of matching articles print(f"Found {len(id_list)} articles published between {start_date_str} and {end_date_str} in {database}") # print(id_list)
排查要点
- 日期字段名错误:PMC数据库中,对应文章出版日期的检索字段是
[Date - Publication],而非代码里写的[Publication Date]。NCBI不同数据库的检索字段命名有差异,这是导致日期范围过滤失效的核心原因。 - 开放获取过滤条件过严:代码中添加的
open_access[filter]可能排除了目标文章——PMC10003631可能不属于开放获取文章,或者该过滤条件的语法在PMC检索中不适用。建议先去掉该过滤条件测试,再根据实际需求调整。 - 手动验证检索逻辑:直接在NCBI官网的PMC检索页面输入修正后的检索词:
("2023/03/01"[Date - Publication] : "2023/03/22"[Date - Publication]) AND dosage compensation[Title/Abstract],确认是否能搜到目标PMC文章,以此验证检索逻辑的正确性。
内容的提问来源于stack exchange,提问作者Wasim Aftab
相关产品推荐
相关产品推荐

