扫码关注官方订阅号
今天在学习bs4的解析html中 发现有解析各种标签中的内容的语句,但是未找到能解析出h1 h2 h3 h4这些标签中的文字的语句和参数啊,请问该如何进行筛选呢?
光阴似箭催人老,日月如移越少年。
>>> from bs4 import BeautifulSoup >>> html = """ <html> <h1 align="center">This is heading 1</h1> </html> """ >>> soup = BeautifulSoup(html,'html.parser') >>> res = soup.find('h1').get_text() >>> print(res) This is heading 1
像这样吗?
h1.string
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
像这样吗?
h1.string