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))
相关推荐
程序员ken19 分钟前
深入理解大语言模型(8) 使用 LangChain 开发应用程序之上下文记忆
人工智能·python·语言模型·langchain
wazmlp00188736927 分钟前
第五次python作业
服务器·开发语言·python
尘缘浮梦29 分钟前
websockets简单例子1
开发语言·python
不懒不懒30 分钟前
【从零开始:PyTorch实现MNIST手写数字识别全流程解析】
人工智能·pytorch·python
helloworld也报错?30 分钟前
基于CrewAI创建一个简单的智能体
人工智能·python·vllm
啊阿狸不会拉杆43 分钟前
《机器学习导论》第 10 章-线性判别式
人工智能·python·算法·机器学习·numpy·lda·线性判别式
超龄超能程序猿44 分钟前
Python 反射入门实践
开发语言·python
玄同7651 小时前
Python Random 模块深度解析:从基础 API 到 AI / 大模型工程化实践
人工智能·笔记·python·学习·算法·语言模型·llm
AIFarmer1 小时前
在EV3上运行Python语言——环境设置
python·ev3