Beautiful Soup库的安装

Beautiful Soup库的安装

1.简介

Beautiful Soup库是解析、遍历、维护“标签树”的功能库。它对应一个HTML/XML文档的全部内容。Beautiful Soup库也叫beautifulsoup4或者bs4。常用引入方法为:

from bs4 import BeautifulSoup

2.安装

2.1 以管理员身份运行cmd命令台

2.2 在命令台上执行以下代码:

pip install beautifulsoup4

这里写图片描述

2.3 测验是否安装成功

import requests
r=requests.get("https://python123.io/ws/demo.html")
demo=r.text
from bs4 import BeautifulSoup #导入类
soup=BeautifulSoup(demo,"html.parser")#对demo进行html的解析
print(soup.prettify())

运行结果

<html>
 <head>
  <title>
   This is a python demo page
  </title>
 </head>
 <body>
  <p class="title">
   <b>
    The demo python introduces several python courses.
   </b>
  </p>
  <p class="course">
   Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses:
   <a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1">
    Basic Python
   </a>
   and
   <a class="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2">
    Advanced Python
   </a>
   .
  </p>
 </body>
</html>

猜你喜欢

转载自blog.csdn.net/zhangduan8785/article/details/80421837