0

The code I have is:

    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 = ''

It's working on an HTML page that has meta and title tags (lowercase), so I would expect multiple matches for the meta tags and a nonempty title. Adding or removing parentheses around the regular expression does not seem to make a difference.

1 Answer 1

2

re.search searches for the first match. You need to use re.findall or re.finditer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.