1

I'm trying to get the contents of a <ul> tag from a webpage in python. I used the following code:
matchResult = re.search(r'<ul\s*content="MSL">(.*)</ul>', queryResult, re.MULTILINE)
This does not work. However if I remove the line breaks by using
queryResult = queryResult.replace('\r','').replace('\n','')
It works.

This regular expression in PHP works fine without removing line breaks: preg_match('@<ul\s*content="MSL">(.*)</ul>@msU', $queryResult, $matches);

How can I match over multiple lines using Python?

1 Answer 1

5

Include the re.DOTALL option as well, that will allow the . character to match newlines.

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.