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))
相关推荐
子夜江寒1 小时前
基于 OpenCV 的图像形态学与边缘检测
python·opencv·计算机视觉
少林码僧8 小时前
2.31 机器学习神器项目实战:如何在真实项目中应用XGBoost等算法
人工智能·python·算法·机器学习·ai·数据挖掘
智航GIS8 小时前
10.4 Selenium:Web 自动化测试框架
前端·python·selenium·测试工具
jarreyer8 小时前
摄像头相关记录
python
宝贝儿好8 小时前
【强化学习】第六章:无模型控制:在轨MC控制、在轨时序差分学习(Sarsa)、离轨学习(Q-learning)
人工智能·python·深度学习·学习·机器学习·机器人
大、男人8 小时前
python之asynccontextmanager学习
开发语言·python·学习
默默前行的虫虫9 小时前
nicegui文件上传归纳
python
一个没有本领的人9 小时前
UIU-Net运行记录
python
国强_dev10 小时前
Python 的“非直接原因”报错
开发语言·python
副露のmagic10 小时前
更弱智的算法学习 day24
python·学习·算法