beautifulsoup匹配
BeautifulSoup是Python的一个库,最主要的功能就是从网页匹配我们需要的数据。
BeautifulSoup将html解析为对象进行处理,全部页面转变为字典或者数组,相对于正则表达式的方式,可以大大简化处理过程。
安装:pip3 install beautifulsoup4
Beautifulsoup和xpath的使用结构大同小异
beautifulsoup匹配步骤
导入模块:from bs4 import BeautifulSoup
(1)构建beautifulsoup实例
# coding:utf-8
import requests
from bs4 import BeautifulSoup
html = '''
<html>
<head>
<title>test</title>
</head>
<body>
<div>
<ul>
<li name="suner" class="one"><a>suner</a></li>
<li name="wjk" class="two">wjk</li>
<li name="wang" class="three">wang</li>
<li name="karry