I'm using BeautifulSoup to scrape data from a website. I want to display the extracted data on a separate HTML page.
Unfortunately, to send said data, I'm using Flask, which only allows me to send data to render_template, which as far as I understand requires your HTML files to be in a "template" folder.
I want the data to be displayed within a <p> element on index.html, which I don't want to be in another folder.
Here's the code that runs on main.py
(I'm running everything on a server)
from flask import Flask, render_template
app=Flask(__name__)
from bs4 import BeautifulSoup
import requests
#Scraping starts
url = "https://example.com"
req = requests.get(url)
bs0bj = BeautifulSoup (req.text, "html.parser")
data=bs0bj.find_all('div', {"class": "exampleClass"})
data=data[0].text
data=data.strip()
#Send to index.html
@app.route('/')
def home():
return render_template('index.html',data=data)
You should be able to display the received data in html with something like
<p>{{data}}</p>
I can't seem to find a way to send the data from main.py to index.html, and how to receive the data from main.py inside index.html
Other options that don't use Flask are also welcome.