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))
相关推荐
m0_602857768 分钟前
如何提升SQL存储过程逻辑复用_封装通用存储过程函数
jvm·数据库·python
傻啦嘿哟1 小时前
如何在 Python 中使用 colorama 库来给输出添加颜色
开发语言·python
forEverPlume1 小时前
mysql如何实现高可用集群架构_基于MHA环境搭建与部署
jvm·数据库·python
方安乐6 小时前
python之向量、向量和、向量点积
开发语言·python·numpy
zh1570237 小时前
JavaScript中WorkerThreads解决服务端计算瓶颈
jvm·数据库·python
蜡台8 小时前
Python包管理工具pip完全指南-----2
linux·windows·python
Mr.朱鹏8 小时前
【Python 进阶 | 第四篇】Psycopg3 + Flask 实现 PostgreSQL CRUD 全流程:从连接池到RESTful接口
python·postgresql·flask·virtualenv·fastapi·pip·tornado
2401_871492859 小时前
Vue.js监听器watch利用回调函数处理级联下拉框数据联动
jvm·数据库·python
FreakStudio9 小时前
亲测可用!可本地部署的 MicroPython 开源仿真器
python·单片机·嵌入式·面向对象·并行计算·电子diy·电子计算机
SilentSamsara10 小时前
Python 环境搭建完整指南:从下载安装到运行第一个程序
开发语言·python