微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

浏览器搜索与Bio.entrez搜索的结果不同

如何解决浏览器搜索与Bio.entrez搜索的结果不同

使用Bio Entrez进行搜索时,得到的结果有所不同。例如,当我在浏览器上使用查询“ covid side effect”搜索时,得到344个结果,而当我使用Bio Entrez时,我只有92个结果。这是我正在使用的代码

from Bio import Entrez
Entrez.email = "Your.Name.Here@example.org"
handle = Entrez.esearch(db="pubmed",retmax=40,term="covid side effect",idtype="acc")
record = Entrez.read(handle)
handle.close()
print(record['Count'])

我希望有人能帮助我解决这个问题。

解决方法

由于某种原因,无论是R api还是Python API,每个人似乎都有相同的问题。我发现周围的工作可以得到相同的结果。它很慢,但是可以完成工作。如果结果少于1万,则可以使用Selenium来获取pubmedid。否则,我们可以使用下面的代码抓取数据。我希望这会对以后的人有所帮助。

import requests
# # Custom Date Range
# req = requests.get("https://pubmed.ncbi.nlm.nih.gov/?term=covid&filter=dates.2009/01/01-2020/03/01&format=pmid&sort=pubdate&size=200&page={}".format(i))

# # Custom Year Range
# req = requests.get("https://pubmed.ncbi.nlm.nih.gov/?term=covid&filter=years.2010-2019&format=pmid&sort=pubdate&size=200&page={}".format(i))


# #Relative Date 
# req = requests.get("https://pubmed.ncbi.nlm.nih.gov/?term=covid&filter=datesearch.y_1&format=pmid&sort=pubdate&size=200&page={}".format(i))

# # filter language 
# # &filter=lang.english

# # filter human 
# #&filter=hum_ani.humans

# Systematic Review
#&filter=pubt.systematicreview

# Case Reports 
# &filter=pubt.casereports

# Age
# &filter=age.newborn

search = "covid lungs"
# search_list = "+".join(search.split(' '))

def id_retriever(search_string):
    string = "+".join(search_string.split(' '))
    result = []
    old_result = len(result)
    for page in range(1,10000000):
        req = requests.get("https://pubmed.ncbi.nlm.nih.gov/?term={string}&format=pmid&sort=pubdate&size=200&page={page}".format(page=page,string=string))

        for j in req.iter_lines():
            decoded = j.decode("utf-8").strip(" ")
            length = len(decoded)
            if "log_displayeduids" in decoded and length > 46:
                data = (str(j).split('"')[-2].split(","))
                result = result + data
                data = []
        new_result = len(result)
        if new_result != old_result:
            old_result = new_result
        else:
            break
    return result

ids=id_retriever(search)
len(ids)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。