分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

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

发布时间:2023-11-01 15:52责任编辑:傅花花关键词:HTML
#Author:Alex.Zhangimport urllib.requestimport repmids=[‘18235848‘,‘18235847‘,‘18235849‘]count=0for 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的不同号输进去就会为你生成一系列的文档啦!

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

原文地址:https://www.cnblogs.com/klausage/p/10804249.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved