Spaces:
Runtime error
Runtime error
import requests | |
from bs4 import BeautifulSoup | |
def scrape_url(url): | |
"""Fetch and extract text from a webpage.""" | |
try: | |
res = requests.get(url, timeout=10) | |
res.raise_for_status() | |
soup = BeautifulSoup(res.text, 'html.parser') | |
return soup.get_text(separator='\n', strip=True) | |
except Exception as e: | |
return f"[Error scraping {url}: {e}]" |