Classwork 5 - Check the HTML Tags

python 复制代码
#获取html的tag

html = ['<body>Welcome to our course! It would be an awesome experience</body>',
 '<article>To be a data scientist, you need to have knowledge in statistics and mathematics</article>',
 '<nav>About me Links Contact me!']
import  re


for s in html:
    match_tag= re.match(r"<(\w+)>.*?</\1>",s)
    if match_tag:
        tag_name = match_tag.group(1)
        print(f"you can find tag:{tag_name}")  ## 加 f 前缀,{tag_name} 会替换为实际标签名


for s in html:
    match_tag = re.match(r"<(\w+)>.*?</\1>", s)
    if match_tag:
        tag_name = match_tag.group(1)
        print("you can find tag:{tag_name}".format(tag_name=tag_name))
相关推荐
idwangzhen4 分钟前
GEO优化系统哪个功能强大
python·信息可视化
许泽宇的技术分享24 分钟前
第 1 章:认识 Claude Code
开发语言·人工智能·python
AIFQuant38 分钟前
如何利用免费股票 API 构建量化交易策略:实战分享
开发语言·python·websocket·金融·restful
布局呆星1 小时前
SQLite数据库的介绍与使用
数据库·python
2401_838472511 小时前
用Python和Twilio构建短信通知系统
jvm·数据库·python
weixin_452159551 小时前
如何从Python初学者进阶为专家?
jvm·数据库·python
Hello.Reader1 小时前
面向 403 与域名频繁变更的合规爬虫工程实践以 Libvio 系站点为例
爬虫·python·网络爬虫
深蓝海拓1 小时前
PySide6从0开始学习的笔记(二十五) Qt窗口对象的生命周期和及时销毁
笔记·python·qt·学习·pyqt
Dfreedom.1 小时前
开运算与闭运算:图像形态学中的“清道夫”与“修复匠”
图像处理·python·opencv·开运算·闭运算
2301_790300961 小时前
用Python读取和处理NASA公开API数据
jvm·数据库·python