学习www.网for站asp制.cn作
 python 通过 正则获取tag内容,直接看下面函数
 
参数为tag 为 标签只
string 为字符串
strip 布尔 为是否去除前后空格 


import re


def extract_between_tags(tag: str, string: str, strip: bool = False) -> list[str]:
ext_list = re.findall(f"<{tag}>(.+?)</{tag}>", string, re.DOTALL)
if strip:
ext_list = [e.strip() for e in ext_list]
return ext_list


function_calling_message = "asdf<tr>this is forasp.cn</tr>"
match_data = extract_between_tags("tr", function_calling_message, True)
if len(match_data) > 0:
print(match_data[0]) else: print("no match")