文章详情页
python的bs4如何筛选出h1标签中的内容
浏览:339日期:2022-09-15 13:55:06
问题描述
今天在学习bs4的解析html中 发现有解析各种标签中的内容的语句,但是未找到能解析出h1 h2 h3 h4这些标签中的文字的语句和参数啊,请问该如何进行筛选呢?
问题解答
回答1:>>> 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
像这样吗?
回答2:h1.string
相关文章:
1. docker-machine添加一个已有的docker主机问题2. nignx - docker内nginx 80端口被占用3. javascript - 移动端 点击弹出遮罩层 加断点调试就行 不加断点就不行4. javascript - 正则匹配字符串特定语句后的数字5. 关于docker下的nginx压力测试6. angular.js使用$resource服务把数据存入mongodb的问题。7. docker安装后出现Cannot connect to the Docker daemon.8. debian - docker依赖的aufs-tools源码哪里可以找到啊?9. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?10. docker容器呢SSH为什么连不通呢?
排行榜

网公网安备