BeautifulSoup4 解析库的使用Day03-6

#!/usr/bin/env python
#coding: utf8
#python2
#BeautifulSoup4 解析库的使用

from bs4 import BeautifulSoup
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>
"""
#python 自带的解析库
#soup = BeautifulSoup(html_doc,'html.parser')

#调用bs4对象实例化一个soup对象
soup = BeautifulSoup(html_doc,'lxml')

#bs4对象
print(soup)

print('\n')
print('\n')
print('\n')
#bs4类型
print(type(soup))

#美化功能
html = soup.prettify()
print(html)

猜你喜欢

转载自www.cnblogs.com/zxdhahaha/p/11128288.html