python爬虫(三):BeautifulSoup 【2. 标签的操作】

可以找到标签,

可以提取标签名字、标签属性、标签内字符串、注释内容等

BeautifulSoup类的基本元素

<p class=“title”> … </p>

基本元素 说明

Tag html标签,如<p>...</p>

Name 标签的名字,格式:<tag>.name,如<p>.name

Attributes 标签的属性,字典形式组织,格式:<tag>.attrs,如<p>.attrs

NavigableString 标签内非属性字符串,<>…</>中字符串,格式:<tag>.string,如<p>.string

Comment 标签内字符串的注释部分,一种特殊的Comment类型

使用方法:

(1)Tag(标签)使用方法

接上一节继续敲代码

soup = BeautifulSoup(demo, 'html.parser')

soup.title

猜你喜欢

转载自blog.csdn.net/weixin_42490528/article/details/84845355