BeautifulSoup4的详解+PubMed医学文献爬取

本文详细介绍了如何使用BeautifulSoup4爬取PubMed网站的医学文献标题、摘要和PMID,包括安装、基本使用方法以及通过CSS选择器定位特定元素的实战示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击名片关注 阿尘blog,一起学习,一起成长

本文主要介绍了BeautifulSoup4的使用和实践:PubMed医学文献标题、摘要、pmid的爬取

01

BeautifulSoup4

安装及初步使用

安装

pip install beautifulsoup4 -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
使用

可以将一个文档传入BeautifulSoup的构造方法,也可以传入一段字符串或句柄

#导入方法
from bs4 import BeautifulSoup
#实例化
soup = BeautifulSoup(open("index.html"))
soup = BeautifulSoup("<html>data</html>")

BeautifulSoup会根据传入的文档来选择最合适的解析器,当然这也是可以自定义的

源码

def __init__(self, markup="", features=None, builder=None,
             parse_only=None, from_encoding=None, exclude_encodings=None,
             element_classes=None, **kwargs):
    """Constructor.


    :param markup: A string or a file-like object representing
     markup to be parsed.


    :param features: Desirable features of the parser to be
     used. This may be the name of a specific parser ("lxml",
     "lxml-xml", "html.parser", or "html5lib") or it may be the
     type of markup to be used ("html", "html5", "xml"). It's
     recommended that you name a specific parser, so that
     Beautiful Soup gives you the same results across platforms
     and virtual environments.


    :param builder: A TreeBuilder subclass to instantiate (or
     instance to use) instead of looking one up based on
     `features`. You only need to use this if you've implemented a
     custom TreeBuilder.


    :param parse_only: A SoupStrainer. Only parts of the document
     matching the SoupStrainer will be considered. This is useful
     when parsing part of a document that would o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是阿尘呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值