Spaces:
Sleeping
Sleeping
AngelaKkkkkkkkk
commited on
Commit
•
1c57ff6
1
Parent(s):
e74b272
Update app.py (#1)
Browse files- Update app.py (7ba5c3e7783dd68c2e06d3f1f341f7f8003120ec)
app.py
CHANGED
@@ -1,14 +1,44 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
# Gradio
|
7 |
with gr.Blocks() as demo:
|
8 |
-
|
9 |
-
output = gr.Textbox(label="
|
10 |
-
|
|
|
11 |
|
12 |
-
|
|
|
13 |
|
14 |
demo.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
|
5 |
+
# Function to scrape a specific website (https://chatgpt.com/)
|
6 |
+
def scrape_website(url):
|
7 |
+
try:
|
8 |
+
# Send a request to the website
|
9 |
+
response = requests.get(url, allow_redirects=True) # This will handle redirects automatically
|
10 |
+
|
11 |
+
# Check if the response was successful
|
12 |
+
if response.status_code == 200:
|
13 |
+
# Parse the page content
|
14 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
15 |
+
|
16 |
+
# Extract the title of the webpage
|
17 |
+
title = soup.find('title').get_text()
|
18 |
+
|
19 |
+
# Extract the meta description if available
|
20 |
+
meta_description = soup.find('meta', attrs={'name': 'description'})
|
21 |
+
if meta_description:
|
22 |
+
meta_description = meta_description.get('content')
|
23 |
+
else:
|
24 |
+
meta_description = "No meta description available"
|
25 |
+
|
26 |
+
return f"Title: {title}\nMeta Description: {meta_description}"
|
27 |
+
else:
|
28 |
+
return f"Failed to access {url} (status code: {response.status_code})"
|
29 |
+
|
30 |
+
except Exception as e:
|
31 |
+
return f"An error occurred: {str(e)}"
|
32 |
|
33 |
+
# Gradio interface to input URL and display scraped content
|
34 |
with gr.Blocks() as demo:
|
35 |
+
url_input = gr.Textbox(value="https://chatgpt.com", label="URL", placeholder="Enter URL")
|
36 |
+
output = gr.Textbox(label="Scraped Data")
|
37 |
+
|
38 |
+
submit_btn = gr.Button("Scrape Website")
|
39 |
|
40 |
+
# Set the button action
|
41 |
+
submit_btn.click(scrape_website, url_input, output)
|
42 |
|
43 |
demo.launch()
|
44 |
+
|