Spaces:
Sleeping
Sleeping
Download app.py from ENLYAS/web-scraper-app: direct link, hf CLI and curl.
- Browser
- Download file 913 Bytes
-
https://huggingface.co/spaces/ENLYAS/web-scraper-app/resolve/main/app.py
- Command line
-
hf download hf://spaces/ENLYAS/web-scraper-app/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ENLYAS/web-scraper-app/resolve/main/app.py
913 Bytes
| import gradio as gr | |
| import requests | |
| from bs4 import BeautifulSoup | |
| def scrape_site(url): | |
| try: | |
| headers = {"User-Agent": "Mozilla/5.0"} | |
| r = requests.get(url, headers=headers, timeout=10) | |
| r.raise_for_status() | |
| soup = BeautifulSoup(r.text, "html.parser") | |
| title = soup.title.string.strip() if soup.title else "N/A" | |
| body = soup.get_text(separator=" ", strip=True)[:1000] | |
| return f"Title: {title}\n\nContent Preview:\n{body}" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Simple Web Scraper") | |
| url_input = gr.Textbox(label="Enter URL", placeholder="https://example.com") | |
| result_output = gr.Textbox(label="Scraped Content", lines=10) | |
| submit_btn = gr.Button("Scrape") | |
| submit_btn.click(fn=scrape_site, inputs=url_input, outputs=result_output) | |
| if __name__ == "__main__": | |
| demo.launch() |