File size: 384 Bytes
1349210
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
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}]"