从PubMed的HTML页面提取标题和摘要文本

#Author:Alex.Zhang
import urllib.request
import re
pmids=['18235848','18235847','18235849']
count=0
for pmid in pmids:
    count+=1
    url='https://www.ncbi.nlm.nih.gov/pubmed/?term=%s'%pmid
    handler=urllib.request.urlopen(url)
    html=handler.read()


    title_regexp=re.compile('<h1>.{5,400}</h1>')
    title_text=title_regexp.search(html.decode('utf-8'))
    abstract_regexp=re.compile('<h3>Abstract</h3><div class\=""><p>.{20,3000}</p></div>')
    abstract_text=abstract_regexp.search(html.decode('utf-8'))
    titlee='abstract'+str(count)
    with open(titlee,'w',encoding='utf-8') as en:
        en.write('tile')
        en.write(title_text.group())
        en.write('\n')
        en.write('abstract:')
        en.write(abstract_text.group())

    print('Title:',title_text.group())
    print('abstract:',abstract_text.group())

只需要把PMIDS的不同号输进去就会为你生成一系列的文档啦!

转载于:https://www.cnblogs.com/klausage/p/10804249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值