python爬虫:BF4安装与使用
''' 安装解析器: pip3 install lxml 安装解析库: pip3 install bs4 ''' html_doc = ''' <html><head><title>The Dormouse's story</title></head> <body> <p class="sister"><b>$37</b></p> <p class="story" id="p">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" >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 # python自带解析库 # soup = BeautifulSoup(html_doc,'html.parser') # 调用bs4得到 一个soup对象 soup = BeautifulSoup(html_doc,'lxml') # bs4对象 print(soup) # bs4类型 print(type(soup)) # 美化功能 html = soup.prettify() print(html)