Beautiful Soup4安装及使用-fqcd0003

时间:2024-03-22 07:39:25

BeaufifulSoup安装步骤如下:

1.进入阿里云开发者社区下载(http://mirrors.aliyun.com/pypi/simple/beautifulsoup4/);

2.选择tar后缀的文件,比如beautifulsoup4-4.8.2.tar下载;

3.运行CMD,pip install beautifulsoup4,即可安装;

4.使用方法参考https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/index.html

5.lxml是Python语言和XML以及HTML工作的功能最丰富和最容易使用的库。安装完beautifulsoup后,安装lxml,

运行cmd,pip install lxml即可安装。

BeaufifulSoup使用步骤如下:

1.使用举例:

************************************************输入代码**********************************************************

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')

print(soup.prettify())

*********************************************************输出内容************************************************

Beautiful Soup4安装及使用-fqcd0003