unclegood
unclegood

Reputation: 289

BeautifulSoup prettify output into html

I am trying to make output like below. enter image description here

But I got this instead. enter image description here

Below is my flask code:

@app.route('/finance')
def finance():
    page = requests.get("http://dataquestio.github.io/web-scraping-pages/simple.html")
    soup = BeautifulSoup(page.content, 'html.parser')
    soup = soup.prettify()
    return render_template('finance.html', page=page, soup=soup)

HTML code:

{{ soup }}

How can I achieve the neat format in the first image?

Upvotes: 1

Views: 170

Answers (1)

Dinko Pehar
Dinko Pehar

Reputation: 6061

As user Nico Haase mention, you should wrap your code in pre tag. I tried it locally, it works.

<pre>
{{ soup }}
</pre>

Upvotes: 1

Related Questions