BeautifulSoup4 parsing library use 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 comes parsing library 
# soup = BeautifulSoup (html_doc, 'html.parser') 

# call object instance of a soup bs4 objects 
soup = BeautifulSoup (html_doc, ' lxml ' ) 

# BS4 objects 
Print (Soup) 

Print ( ' \ n- ' )
 Print ( ' \ n- ' )
 Print ( ' \ n- ' )
 # BS4 type 
Print (type (Soup)) 

# beautification 
html = soup.
prettify()
print(html)

 

Guess you like

Origin www.cnblogs.com/zxdhahaha/p/11128288.html