直接看例子:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
html_doc = """
The Dormouse's storyThe Dormouse's story
Once upon a time there were three little sisters; and their names were
Lacie and
and they lived at the bottom of a well.
...
"""
soup = BeautifulSoup(html_doc)
print soup.title
print soup.title.name
print soup.title.string
print soup.p
print soup.a
print soup.find_all('a')
print soup.find(id='link3')
<
本文详细介绍了Python的BeautifulSoup库的使用方法,包括获取title、p、a等标签,find_all函数的使用,以及如何获取标签属性、内容数组、子节点等。此外,还讲解了如何通过CSS选择器和属性进行查找,以及限制查找结果的数量。
最低0.47元/天 解锁文章
1460

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



