12 Beautiful Soup库的安装

 

BeautifulSoup库的安装

Pip install BeautifulSoup4  (anaconda第三方库中已安装BeautifulSoup库)

测试

 1 """BeautifulSoup安装测试"""
 2 
 3 
 4 import requests
 5 from bs4 import BeautifulSoup
 6 
 7 url = "https://python123.io/ws/demo.html"
 8 r = requests.get(url)
 9 demo = r.text
10 soup = BeautifulSoup(demo, "html.parser")
11 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>

 

posted @ 2020-06-04 17:02  udbful  阅读(333)  评论(0)    收藏  举报