-1

I have tried all the StackOverflow solutions for similar questions, and could`t find anything.

I have this snippet of code and I need to extract the text between html tags, everything between > and < .

word = "div class="name">
                        Text_I_Want_To_Extract 
                    </div>"

m = re.search('>(.+)<', word)
print (m)

I have tried various regex expressions but I failed. I always get empty result. I am guessing it is because I am extracting everything between > and < symbols.

Did anyone had this kind of problems with Python 3 ?

Adrian Ivasku
  • 1,010
  • 3
  • 12
  • 27

1 Answers1

0

Try using flags

Ex:

import re

word = """div class="name">
                        Text_I_Want_To_Extract 
                    </div>"""

m = re.search('>(.+)<', word, flags=re.DOTALL)
print (m.group(1).strip())

Output:

Text_I_Want_To_Extract
Rakesh
  • 75,210
  • 17
  • 57
  • 95