Filter strings into list depending on position - Python
Question: For example, this is my string:

    
    
    myString = "<html><body><p>Hello World!</p><p>Hello Dennis!</p></body></html>"
    

and what i am trying to achieve is:

    
    
    myList = ['Hello World!','Hello Dennis!']
    

Using regular expressions or another method, how can i filter out paragraph
text out of `myString` while ignoring the html tags to achieve `myList`?

I have tried:

    
    
    import re
    a="<body><p>Hello world!</p><p>Hello Denniss!</p></body>"
    result=re.search('<p>(.*)</p>', a)
    print result.group(1)
    

Which resulted in: `Hello world!</p><p>Hello Denniss!` and when i tried
`(.*)(.*)` i got `Hello World!`

This string is just an example. The string may also be
`<garbage>abcdefghijk<gar<bage>` depending on how the web developer coded the
website.

It may be a complex regex, but i need to learn this as it is for a cyber
security competition i will be participating in later this year and i think my
best bet is to develop an algorithm which searches for text between a `>` and
a `<`.

How would i go about this?

Sorry if my question is not formatted properly, i have a bit of learning
problems.


Answer: Do you want to get rid of all tags in a `html` text? I won't choose regular
expression, better _the other method_ , for example with `BeautifulSoup` and
you will surprise all in that hacking meeting:

    
    
    from bs4 import BeautifulSoup
    
    myString = "<html><body><p>Hello World!</p><p>Hello Dennis!</p></body></html>"
    
    myList = list(BeautifulSoup(myString).strings))
    

It yields:

    
    
    ['Hello World!', 'Hello Dennis!']
    

