为什么这个Python正则表达式代码只能找到空结果?

为什么这个Python正则表达式代码只能找到空结果?,python,html,regex,parsing,css,Python,Html,Regex,Parsing,Css,我的密码是: 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 titl

我的密码是:

    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 = ''
matches=re.search(“()”,contents,re.DOTALL)
如果匹配:
对于匹配项中的组。组()
元附加(组)
title=re.search(“(.*”),contents,re.DOTALL)
如果title.groups():
找到\u title=title.group(1)+'\n'
其他:
已找到标题=“”

它在一个HTML页面上工作,该页面有meta和title标记(小写),因此我希望meta标记和非空标题有多个匹配项。在正则表达式周围添加或删除括号似乎没有什么区别。

re.search
搜索第一个匹配项。您需要使用
re.findall
re.finditer