作者:IT小样
通过之前的系列我们现在已经了解了BeautifulSoup的属性、操作,现在我们来一起学习一下如何搜索文档树。
1、find_all()方法
find_all()方法,找到所有匹配,关于传入参数,可以传入各种类型,接下来介绍不同过滤器。
1.1、过滤器
1.1.1、字符串过滤器
仍然以之前的html_doc为例,来进行示范:
html_doc = '''
<html><head><title>hello,tester</title></head><body>
<p class="title"><b><h1>Hello,welcome</h1></b></p>
<p class="documentation">Tester, welcome! This is a new partion of your job's life. With python, you can finnish your work easier and faster.How, <a href="http://example.com/easier" class="easier" id="link1"> easier </a> and <a href="http://example.com/faster" class="faster" id = "link2">faster

本文介绍了Python爬虫中BeautifulSoup库的搜索文档树方法,包括find_all()、find()及其详细参数,如name、attrs、class_等,并提到了过滤器的多种类型,如字符串、正则表达式和自定义方法。
最低0.47元/天 解锁文章
318

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



