文章详情页
python的bs4如何筛选出h1标签中的内容
浏览:385日期: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. android - Home键app重新启动的问题2. javascript - 求助这种功能有什么好点的插件?3. 前端 - html5 audio不能播放4. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””5. phpstudy pro小皮面板经常报这个nginx: [emerg] CreateFile【急】6. 自学,刚编了helloworld就失败了7. python3.x - mongodb 显示不出中文,都是方块,该如何解决?8. android - 微信这个效果是怎么实现的9. Python 爬虫字符编码问题,求解。10. 为啥最大化个窗口还得找一堆理由?
排行榜

网公网安备