爬虫利器BeautifulSoup模块使用
发布时间:2020-12-16 23:56:33 所属栏目:Python 来源:网络整理
导读:table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0" tr td span style="font-size: 16px;"一、简介 /td /tr /table BeautifulSoup?是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换
<table style="height: 30px; background-color: #afeeee; width: 1266px; ; width: 1266px;" border="0"> |
2.安装解析器(可以使用内置的解析器)
$ apt-get install Python-
3.各个解释器优缺点比较
将一段文档传入BeautifulSoup 的构造方法,就能得到一个文档的对象,可以传入一段字符串或一个文件句柄。
bs4 soup = BeautifulSoup(open(<span style="color: #800000;">"<span style="color: #800000;">index.html<span style="color: #800000;">"<span style="color: #000000;">))
<span style="color: #008000;">#<span style="color: #008000;">##使用解释器###
soup = BeautifulSoup(open(<span style="color: #800000;">"<span style="color: #800000;">index.html<span style="color: #800000;">"),features=<span style="color: #800000;">"<span style="color: #800000;">lxml<span style="color: #800000;">")
soup = BeautifulSoup(<span style="color: #800000;">"<span style="color: #800000;">
...<span style="color: #800000;">"<span style="color: #000000;">)<span style="color: #008000;">#<span style="color: #008000;">##使用解释器###
soup = BeautifulSoup(open(<span style="color: #800000;">"<span style="color: #800000;">index.html<span style="color: #800000;">"),features=<span style="color: #800000;">"<span style="color: #800000;">lxml<span style="color: #800000;">")
基本使用
使用html示例
bs4 = test
wd