find_all
用来查询所有节点的方法
案例1:查询所有的a标签
from bs4 import BeautifulSoup
html = """
<html>
<head>
<title>优课达</title>
</head>
<body>
<a href="https://www.youkeda.com" alt="学得比别人好一点">优课达</a>
<ul>
<li><a href="https://www.youkeda.com">问吧</a></li>
<li class="info"><a href="https://www.youkeda.com/academy/java">研发学院</a></li>
<li class="info"><a href="https://www.youkeda.com/academy/python/P2">Python学院</a></li>
<li class="info last"><a class="download" href="https://www.youkeda.com/app">APP下载</a></li>
</ul>
</body>
</html>
"""
result = BeautifulSoup(html, 'html.parser')
# 查询所有的a标签
aList = result.find_all('a')
print(aList)
结果为
[
<a alt="学得比别人好一点" href="https://www.youkeda.com">优课达</a>,
<a href

本文是关于Python爬虫中Beautiful Soup库的使用笔记,重点介绍了find_all和select方法。find_all用于查找所有指定标签,如查找所有a标签、class为info的li标签及特定href属性的a标签。在处理class属性时,由于'python'是关键词,需使用class_。同时,展示了如何结合使用find_all获取内部class为download的a元素文字内容。select方法则通过CSS选择器进行筛选,简化了查询过程。
最低0.47元/天 解锁文章
774

被折叠的 条评论
为什么被折叠?



