python爬虫:BF4安装与使用
Posted auraro997
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
以上是关于python爬虫:BF4安装与使用的主要内容,如果未能解决你的问题,请参考以下文章
Python爬虫入门教程 44-100 Charles的安装与使用-手机APP爬虫部分