码迷,mamicode.com
首页 > 编程语言 > 详细

python爬虫:BF4安装与使用

时间:2019-07-03 20:20:47      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:title   html   解析   head   美化   import   pip3   from   python爬虫   

‘‘‘
安装解析器:
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)

  

python爬虫:BF4安装与使用

标签:title   html   解析   head   美化   import   pip3   from   python爬虫   

原文地址:https://www.cnblogs.com/Auraro997/p/11128167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!