当前位置:网站首页>15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
2022-06-26 14:01:00 【安迪python学习笔记】
15 bs对象.节点名称.节点名称.string 获取嵌套节点内容
15.1 获取嵌套节点内容的方法

语法格式:bs对象.节点名称.节点名称.string
返回的数据类型:<class ‘bs4.element.Tag’> 节点对象
from bs4 import BeautifulSoup
html_str = """<head><title>知否!知否!</head></title>"""
bs_duixiang = BeautifulSoup(html_str,"lxml")
# bs对象.节点名称
print("获取head节点:")
print(bs_duixiang.head,'\n')
# bs对象.节点名称.节点名称
# head 节点里还有有个子节点title
print("获取head节点的子节点title:")
print(bs_duixiang.head.title,'\n')
print("获取获取head节点的子节点title的类型:")
print(type(bs_duixiang.head.title),'\n')
# bs对象.节点名称..节点名称string获取节点内容
print("获取子节点title的内容:")
print(bs_duixiang.head.title.string,'\n')
print("获取子节点title的内容的数据类型:")
print(type(bs_duixiang.head.title.string))
【终端输出】
获取head节点:
<head><title>知否!知否!</title></head>
获取head节点的子节点title:
<title>知否!知否!</title>
获取获取head节点的子节点title的类型:
<class 'bs4.element.Tag'>
获取子节点title的内容:
知否!知否!
获取子节点title的内容的数据类型:
<class 'bs4.element.NavigableString'>
15.2 总结

边栏推荐
- Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
- When drawing with origin, capital letter C will appear in the upper left corner of the chart. The removal method is as follows:
- 【使用yarn运行报错】The engine “node“ is incompatible with this module.
- A remove the underline from the label
- Eigen(3):error: ‘Eigen’ has not been declared
- Electron
- 登录认证服务
- PostGIS create spatial database
- C语言刷题随记 —— 乒乓球比赛
- 权威发布 | 延安大学2022年教师岗位招聘公告
猜你喜欢

Eigen(3):error: ‘Eigen’ has not been declared

'教练,我想打篮球!' —— 给做系统的同学们准备的 AI 学习系列小册

量化框架backtrader之一文读懂observer观测器

Electron

Server create virtual environment run code

Sword finger offer 15.65.56 I 56Ⅱ. Bit operation (simple - medium)

Question bank and answers of the latest Guizhou construction eight (Mechanics) simulated examination in 2022

这才是优美的文件系统挂载方式,亲测有效

赠书 | 《认知控制》:我们的大脑如何完成任务?

Practice with the topic of bit operation force deduction
随机推荐
Sword finger offer 18.22.25.52 Double pointer (simple)
The engine "node" is inconsistent with this module
Sword finger offer 09.30 Stack
wptx64能卸载吗_win10自带的软件哪些可以卸载
Knowledge about the determination coefficient R2 and the relationship with the correlation coefficient
oracle11g数据库导入导出方法教程[通俗易懂]
D - Face Produces Unhappiness
C语言基础知识入门(大全)「建议收藏」
How to convert data in cell cell into data in matrix
工作上对金额价格类小数点的总结以及坑
Error when redis is started: could not create server TCP listening socket *: 6379: bind: address already in use - solution
量化框架backtrader之一文读懂observer观测器
Sword finger offer 45.61 Sort (simple)
MHA高可用配合及故障切换
When drawing with origin, capital letter C will appear in the upper left corner of the chart. The removal method is as follows:
使用宝塔面板部署flask环境
Sectigo的IP证书申请流程
Chinese output of PostGIS console is garbled
Leaflet loading ArcGIS for server map layers
Excerpt from three body