Spaces:
Runtime error
Runtime error
Create # scraper.py
Browse files- # scraper.py +12 -0
# scraper.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
|
4 |
+
def scrape_url(url):
|
5 |
+
"""Fetch and extract text from a webpage."""
|
6 |
+
try:
|
7 |
+
res = requests.get(url, timeout=10)
|
8 |
+
res.raise_for_status()
|
9 |
+
soup = BeautifulSoup(res.text, 'html.parser')
|
10 |
+
return soup.get_text(separator='\n', strip=True)
|
11 |
+
except Exception as e:
|
12 |
+
return f"[Error scraping {url}: {e}]"
|