博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BeautifulSoup库的安装及基本元素
阅读量:1887 次
发布时间:2019-04-26

本文共 854 字,大约阅读时间需要 2 分钟。

一、BeautifulSoup的安装

1.安装beautifu soup

以管理员权限执行cmd,然后执行pip install beautifulsoup4 命令

 

 

 

2.Beautiful Soup库的安装小测

演示HTML页面地址http://python123.io/ws/demo.html

 

3.BeautifulSoup库解析HTML库

from bs4 import BeautifulSoup

soup=BeautifulSoup(‘<p>data</p>,’html.parser’’)

二、BeautifulSoup库的基本元素

1.Beautiful Soup库的引用

Beautiful Soup库,也叫beautifulsoup4或bs4   如:from bs4 import BeautifulSoup

 

2.Beautiful Soup解析器

解析器                      使用方法                     条件

bs4的HTML解析器     BeautifulSoup(mk,’html.parser’)  安装bs4库

lxml的HTML解析器    BeautifulSoup(mk,’lxml’)         pip install lxml

lxml的XML解析器     BeautifulSoup(mk,’xml’)         pip install lxml

html5lib的解析器     BeautifulSoup(mk,’html5lib’) pip install html5lib

 

 

3.Beautiful Soup类的基本元素

基本元素                说明

Tag            标签,最基本的信息组织单元,分别用<>和</>标明开头和结尾

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

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

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

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

你可能感兴趣的文章
2019-09-02 博客热门文章
查看>>
2019-09-05 博客热门文章
查看>>
每周博文精选 第36周
查看>>
2019-09-06 博客热门文章
查看>>
2019-09-09 博客热门文章
查看>>
2019-09-10 博客热门文章
查看>>
2019-09-11 博客热门文章
查看>>
每周博文精选 第37周
查看>>
2019-09-15 博客热门文章
查看>>
2019-09-16 博客热门文章
查看>>
2019-09-17 博客热门文章
查看>>
2019-09-18 博客热门文章
查看>>
2019-09-19 博客热门文章
查看>>
2019-09-22 博客热门文章
查看>>
每周博文精选 第38周
查看>>
2019-09-23 博客热门文章
查看>>
2019-09-27 博客热门文章
查看>>
2019-10-08 博客热门文章
查看>>
2019-10-09 博客热门文章
查看>>
2019-10-10 博客热门文章
查看>>