当前位置:网站首页>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 01:23:00 【Andy Python】
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

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

边栏推荐
- [机缘参悟-30]:鬼谷子-内揵篇-同理心,站在对方的立场,拉近与对方的心理距离
- Music spectrum display toy -- implementation and application of FFT in stm32
- FIFO code implemented in C language
- Computer network knowledge summary (interview)
- Sword finger offer II 096 String interleaving
- CityJSON
- I2C protocol
- ASP.NET cache缓存的用法
- C#使用MySql进行操作
- Flex & Bison 开始
猜你喜欢

数组中的第K个最大元素

Implementation notes of least square fitting conic in stm32

远程增量同步神器rsync

Discrete Mathematics - 01 mathematical logic

Optimized three-dimensional space positioning method and its fast implementation in C language

Template engine - FreeMarker first experience

ADC acquisition noise and comparison between RMS filter and Kalman filter

Design and process analysis of anti backflow circuit for MOS transistor
![[flower carving experience] 11 start esp32c3](/img/ff/d7c266893ef4ef70c6536085927e0e.jpg)
[flower carving experience] 11 start esp32c3

新库上线 | CnOpenData中国新房信息数据
随机推荐
数组中的第K个最大元素
如何有效地推廣產品
Camera - 02 image sensor
A sharp tool for information collection, Google hacker syntax
关于EF翻页查询数据库
远程增量同步神器rsync
Inheritance -- holy grail mode
Daily question: the difference between threads and processes
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown
Etcd database source code analysis -- inter cluster network layer server interface
Making 3D romantic cool photo album [source code attached]
Music spectrum display toy -- implementation and application of FFT in stm32
Design and process analysis of anti backflow circuit for MOS transistor
shell正则表达式
2022安徽省安全员C证考试练习题模拟考试平台操作
MOS管防倒灌电路设计及其过程分析
2022年育婴员(五级)考试试题及答案
When you run the demo using the gin framework, there is an error "listen TCP: 8080: bind: an attempt was made to access a socket in a way forbidden"
Web信息收集,互联网上的裸奔者
Digital circuit - adder