Web Scraper Pro

 import os
import datetime
import csv
from flask import Flask, request, render_template, send_file
from bs4 import BeautifulSoup
import requests
import tempfile

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def root_route():
    if request.method == "POST":
        url = request.form["url"]
        try:
            response = requests.get(url)
            soup = BeautifulSoup(response.text, 'html.parser')
            texts = soup.stripped_strings
            scraped_text = " ".join(texts)
            date_scraped = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            data = [{"Source URL": url, "Scraped Text": scraped_text, "Date Scraped": date_scraped}]
            # Generate CSV content
            csv_content = "Source URL,Scraped Text,Date Scraped\\n"
            csv_content += f"\"{url}\",\"{scraped_text}\",\"{date_scraped}\"\\n"

About this template

Web Scraper Pro: A web app that allows users to input a URL and scrape the text from any webpage, displaying it in a formatted table along with the source URL and date scraped. Users can also download the table as a CSV file.

Introduction to the Web Scraper Pro Template

Welcome to the Web Scraper Pro template! This template is designed to help you create a web application that can scrape text from any webpage. The app allows users to input a URL, scrape the text from the page, and display the results in a formatted table. Additionally, users can download the data as a CSV file. This step-by-step guide will walk you through the process of using this template on the Lazy platform.

Getting Started with the Template

To begin building your web scraping application, click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.

Test: Deploying the App

Once you have the template loaded, press the "Test" button to start the deployment of your app. The Lazy CLI will handle the deployment process, and you won't need to worry about installing libraries or setting up your environment.

Entering Input

After pressing the "Test" button, if the app requires any user input, the Lazy App's CLI interface will prompt you to provide it. For this template, you will be asked to enter the URL of the webpage you want to scrape.

Using the App

Once the app is deployed, you will be provided with a dedicated server link to interact with your new web scraping application. The app features a simple interface where you can enter the URL of the webpage you wish to scrape. After submitting the URL, the app will display the scraped text in a table format on the webpage. You will also have the option to download this data as a CSV file.

Integrating the App

If you wish to integrate the Web Scraper Pro app into another service or frontend, you may need to use the server link provided by Lazy. For example, you could embed the link in an iframe within another webpage or use it as part of a larger system that requires scraped data.

Remember, this template is ideal for creating interactive web applications that require both frontend and backend capabilities. It's not suitable for backend-only applications.

If you encounter any issues or need further assistance, the Lazy customer support team is here to help you make the most out of this template.

Happy building with the Web Scraper Pro template on Lazy!

Category
Last published
July 26, 2024

More templates like this

SecureUserAuthenticator

Develop a secure User Authentication system for users to register, log in, and manage their profiles, laying the foundation for user-specific data management and permissions in the CMS.

Laravel
Python
Flask
Javascript

Simple Multiplayer Telegram game

This app is a simple frontend for a game where users can upvote and downvote the most popular word in their country, learn about the flags of other countries, and view what other people voted for on a leaderboard.

Telegram
Python
Javascript

MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.

Python
Flask
Home
/
Web Scraper Pro