I have a function which returns a list like below:
['Title 1', 'Title 2', 'Title 3', 'Title 4']
I have tried numerous ways of implementing the soup.prettify() function to pretty print my list. However can't figure out the exact arrangement to make this work.
Below is my function:
def get_titles(html):
soup = BeautifulSoup(html,'html.parser')
outcome = soup.div.find_all(text=True)
return(outcome)
Calling the function:
html = '#the example html'
print(get_titles(html))
Again, the current outcome (not exact, just an example of the list):
['Title 1', 'Title 2', 'Title 3', 'Title 4']
For clarity, i'm looking to utilise .prettify() to make the outcome list easier to read and therefore 'prettier'.