当前位置:网站首页>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 总结

边栏推荐
- Online bull Blogger
- C | analysis of malloc implementation
- BM3D in popular language
- 登录认证服务
- 挖财注册开户安全吗,有没有什么风险?
- Naacl2022: (code practice) good visual guidance promotes better feature extraction, multimodal named entity recognition (with source code download)
- STM32F1和GD32F1有什么区别?
- Understand the difference and use between jsonarray and jsonobject
- Practical website recommendations worth collecting for College Students
- 量化框架backtrader之一文读懂observer观测器
猜你喜欢

Common controls and custom controls

Leaflet loading ArcGIS for server map layers

Setup instance of layout manager login interface

Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills

C language | Consortium

The annual salary of 500000 is one line, and the annual salary of 1million is another line

权威发布 | 延安大学2022年教师岗位招聘公告

How to mount cloud disks in ECS

vmware部分设置

年薪50万是一条线,年薪100万又是一条线…...
随机推荐
Electron
Excerpt from three body
Knowledge about adsorption
Equation derivation: second order active bandpass filter design! (download: Tutorial + schematic + Video + code)
券商经理给的开户链接安全吗?找谁可以开户啊?
量化框架backtrader之一文读懂observer观测器
STM32F1和GD32F1有什么区别?
Server create virtual environment run code
Practice with the topic of bit operation force deduction
wptx64能卸载吗_win10自带的软件哪些可以卸载
What is the ranking of Guosen Securities? Is it safe to open a stock account?
IP certificate application process of sectigo
PostGIS create spatial database
One article of the quantification framework backtrader read observer
Understand the difference and use between jsonarray and jsonobject
H5关闭当前页面,包括微信浏览器(附源码)
C | analysis of malloc implementation
Leaflet loading ArcGIS for server map layers
Combat readiness mathematical modeling 32 correlation analysis 2
Stream常用操作以及原理探索