File size: 458 Bytes
1349210
 
 
 
 
e4c807c
1349210
863f6b8
e4c807c
 
 
1349210
daac110
1
2
3
4
5
6
7
8
9
10
11
12
13
import requests
from bs4 import BeautifulSoup

def scrape_url(url):
    try:
        res = requests.get(url, timeout=10, headers={'User-Agent': 'Mozilla/5.0'})
        res.raise_for_status()
        soup = BeautifulSoup(res.text, 'html.parser')
        for tag in soup(['script','style','']): tag.decompose()
        text = soup.get_text(separator='\n', strip=True)
        return text
    except Exception as e:
        return f"[Error scraping {url}: {e}]"