我的代码是:
matches = re.search('(<meta.*?>)', contents, re.DOTALL)
if matches:
for group in matches.groups():
metas.append(group)
title = re.search('(<title>.*?</title>)', contents, re.DOTALL)
if title.groups():
found_title = title.group(1) + '\n'
else:
found_title = ''
它正在使用包含元标题和标题标签的HTML页面(小写),因此我希望元标记和非空标题有多个匹配。在正则表达式周围添加或删除括号似乎没有什么区别。
答案 0 :(得分:2)
re.search
搜索第一场比赛。您需要使用re.findall
或re.finditer
。