当前位置:网站首页>15 BS object Node name Node name String get nested node content
15 BS object Node name Node name String get nested node content
2022-06-26 14:44:00 【Andy Python learning notes】
15 bs object . The name of the node . The name of the node .string Get the contents of nested nodes
15.1 Methods to get the contents of nested nodes
List of articles

Grammar format :bs object . The name of the node . The name of the node .string
Data type returned :<class ‘bs4.element.Tag’> Node object
from bs4 import BeautifulSoup
html_str = """<head><title> To know whether ! To know whether !</head></title>"""
bs_duixiang = BeautifulSoup(html_str,"lxml")
# bs object . The name of the node
print(" obtain head node :")
print(bs_duixiang.head,'\n')
# bs object . The name of the node . The name of the node
# head There are also child nodes in the node title
print(" obtain head Child of a node title:")
print(bs_duixiang.head.title,'\n')
print(" Capture the head Child of a node title The type of :")
print(type(bs_duixiang.head.title),'\n')
# bs object . The name of the node .. The name of the node string Get node content
print(" Get child nodes title The content of :")
print(bs_duixiang.head.title.string,'\n')
print(" Get child nodes title Data type of content for :")
print(type(bs_duixiang.head.title.string))
【 Terminal output 】
obtain head node :
<head><title> To know whether ! To know whether !</title></head>
obtain head Child of a node title:
<title> To know whether ! To know whether !</title>
Capture the head Child of a node title The type of :
<class 'bs4.element.Tag'>
Get child nodes title The content of :
To know whether ! To know whether !
Get child nodes title Data type of content for :
<class 'bs4.element.NavigableString'>
15.2 summary

边栏推荐
- 通俗语言说BM3D
- Server create virtual environment run code
- 使用宝塔面板部署flask环境
- One article of the quantification framework backtrader read observer
- Chinese output of PostGIS console is garbled
- 这才是优美的文件系统挂载方式,亲测有效
- ArcGIS secondary development - arcpy delete layer
- Excerpt from three body
- Difference between classification and regression
- 登录认证服务
猜你喜欢

The JVM outputs GC logs, causing the JVM to get stuck. I am stupid

'coach, I want to play basketball!'—— AI Learning Series booklet for system students

Relevant knowledge of information entropy

From Celsius to the three arrows: encrypting the domino of the ten billion giants, and drying up the epic liquidity

How to personalize VIM editor format (DIY)

Related knowledge of libsvm support vector machine

Sword finger offer 05.58 Ⅱ string

How to convert data in cell cell into data in matrix

Sword finger offer 40.41 Sort (medium)

ArcGIS batch export layer script
随机推荐
VIM auto fill auto indent explanation
方程推导:二阶有源带通滤波器设计!(下载:教程+原理图+视频+代码)
【soloπ】adb连接单个多个手机
NAACL2022:(代码实践)好的视觉引导促进更好的特征提取,多模态命名实体识别(附源代码下载)...
启动Redis报错:Could not create Server TCP listening socket *:6379: bind: Address already in use–解决办法
量化框架backtrader之一文读懂observer观测器
ArcGIS batch export layer script
Electron
数学建模经验分享:国赛美赛对比/选题参考/常用技巧
K gold Chef (two conditions, two points and difference)
Eigen(3):error: ‘Eigen’ has not been declared
BM3D in popular language
Pychar remotely connects to the server to run code
VMware partial settings
Atcoder bit operation & Conclusion + formula derivation
Sword finger offer 06.24.35 Linked list
DOS command
What is the ranking of Guosen Securities? Is it safe to open a stock account?
Login authentication service
Common evaluation indexes of classification model -- confusion matrix and ROC curve