import re
读取标题:
result = re.search(r'<title>(.*?)</title>', text, re.DOTALL)
result = re.search(r'<title>(.*?)</title>', text_without_newlines, re.DOTALL)
# 如果找到匹配项,则打印匹配内容
if result:
result_0 = re.sub(r'[a-zA-Z]','', result.group(1))
print(result_0.strip())
response = requests.get(url, headers=headers)
text=response.text
result = re.search(r'<title>(.*?)</title>', text, re.DOTALL)
if result:
name = result.group(1).strip()
name_1 = name.replace("\n", "").replace(" ","")
name_2 = re.sub(r'[a-zA-Z]','',name_1)
filename = rf'D:\1_pyproject\91file\{name_2}.mp4'
本文介绍了如何使用Python中的`re`模块搜索HTML文件中的<title>标签内容,并通过requests库获取网页,最终将处理过的标题用于指定MP4文件名下载相关资源。
284

被折叠的 条评论
为什么被折叠?



