How to put scraped info on your own website?

Question:
How do I take the info that I scraped (that shows up in >_Console) and put it onto my website? In this case I would like to have the scraped links shown on my website.
**Repl link: **
https://replit.com/@Floris2001/web-and-python2#main.py

import requests
from bs4 import BeautifulSoup
from flask import Flask, render_template

#scraper
url = "https://filmhuisdespiegel.nl/programma/"

response = requests.get(url)
html = response.text

soup = BeautifulSoup(html, "html.parser")
links = soup.findAll("a")
for link in links:
  href = link.get("href")
  if href.startswith("/programma"):
    print("https://filmhuisdespiegel.nl"+href)

#website
app = Flask(__name__)

@app.route('/')
def home():
  
  return render_template("index.html")

if __name__ == '__main__':
    app.run(host='0.0.0.0')

Hi @Floris2001 thanks for your question.

One way of making the links feed into your website is to use Python file handling to write the BeautifulSoup output directly to ./templates/index.html

Take a look at my slightly adapted fork here https://replit.com/@IanAtReplit/web-and-python2

1 Like

Thanks!! You helped me a lot!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.