Spaces:
Sleeping
Sleeping
import gradio as gr | |
from selenium import webdriver | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.common.by import By | |
def scrape_website(url): | |
# Create a new instance of the Chrome driver | |
driver = webdriver.Chrome() | |
# Navigate to the provided URL | |
driver.get(url) | |
# Wait until all processes are complete | |
wait = WebDriverWait(driver, 10) # Maximum wait time in seconds | |
wait.until(EC.presence_of_element_located((By.TAG_NAME, 'body'))) | |
# Extract the page title | |
title = driver.title | |
# Close the browser | |
driver.quit() | |
return title | |
# Define the Gradio interface | |
interface = gr.Interface( | |
fn=scrape_website, | |
inputs="text", | |
outputs="text", | |
title="Web Scraping Application", | |
description="Enter a URL to extract the page title." | |
) | |
# Run the Gradio app | |
interface.launch() | |