Spaces:
Running
Running
File size: 608 Bytes
e008495 78a3b6c e008495 1cc2027 e008495 4a8b2d1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from scrapling.fetchers import Fetcher
def scrape_url(url: str) -> str:
try:
page = Fetcher.get(url)
# Extract raw text safely
elements = page.css("body *::text")
texts = []
for el in elements:
try:
# Try extracting text
txt = str(el)
if txt:
texts.append(txt)
except:
continue
cleaned = [t.strip() for t in texts if t.strip()]
return " ".join(cleaned)
except Exception as e:
print("SCRAPING ERROR:", e)
return "" |