为了满足快速浏览pubmed中相关文献标题和摘要的需求,写了个简单的爬虫(目前只实现了单个关键词以及多个关键词的and检索),用于批量获取感兴趣文献的标题和摘要。
使用编辑器是python,所编写的爬虫主要使用requests模块+正则表达式。使用requests.get()来获取请求,使用re模块中re.compile(正则表达式).findall(请求)来获取标题和摘要。代码中对浏览器进行了伪装,但是就只用了2个浏览器。
import requests
import re
key=input("请输入你想查找的信息:")
local_url=input("请输入你想存储的位置及名称:")
turl="https://pubmed.ncbi.nlm.nih.gov/"
tdata=requests.get(turl,params={
"term":key}).text
pat_allpage='<span class="total-pages">(.*?)</span>'
allpage=re.compile(pat_allpage,re.S).findall(tdata)
num=input("请输入大致想获取的文章数目(总数为"+str(int(allpage[0].replace('\n ','').replace