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

边栏推荐
- . Net using access 2010 database
- Music spectrum display toy -- implementation and application of FFT in stm32
- Is it safe for flush software to buy stocks for trading? How to open an account to buy shares
- C another new class is ICO? And app Use of config
- Optimized three-dimensional space positioning method and its fast implementation in C language
- Black box test - decision table method of test cases
- idea配置
- 如何有效地推广产品
- 关于HC-12无线射频模块使用
- 100ask seven day IOT training camp learning notes - bare metal program framework design
猜你喜欢
随机推荐
containerd客户端比较
mysql错误代码2003的解决办法
Etcd database source code analysis -- inter cluster network layer server interface
【花雕体验】11 上手ESP32C3
[learn FPGA programming from scratch -44]: vision chapter - integrated circuit helps high-quality development in the digital era -1- main forms of integrated circuit chips
安卓缓存使用工具类
Optimized three-dimensional space positioning method and its fast implementation in C language
ADC acquisition noise and comparison between RMS filter and Kalman filter
Unknown device ID does not appear on the STM32 st-link utility connection! Causes and Solutions
毕业季你考虑好去留了吗
同花顺上登录股票账户是安全的吗?同花顺上是如何开股票账户的
Classic interview questions: mouse drug test and Hamming code
Redis之Strings命令
Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.
填鸭数据即时收集解决方案资源
在线小工具分享(不定时更新,当前数量:2)
About EF page turning query database
Design and process analysis of anti backflow circuit for MOS transistor
Idempotence of interfaces -- talk about idempotence of interfaces in detail, that is, solutions
RT-Thread 项目工程搭建和配置--(Env Kconfig)









