Spaces:
Sleeping
Sleeping
Update app.py
Browse files42 unmodified lines434445464748497 unmodified lines5758596061626364656642 unmodified lines@tooldef fetch_url_text(url: str) -> str:"""Fetches readable plain text from a given URL.Args:url: The HTTP/HTTPS URL to fetch."""7 unmodified linesheaders={"User-Agent": "Mozilla/5.0"},)response.raise_for_status()raw_html = re.sub(r"(?is)<(script|style).*?>.*?</\1>", " ", response.text)plain_text = re.sub(r"(?s)<[^>]+>", " ", raw_html)cleaned = re.sub(r"\s+", " ", unescape(plain_text)).strip()return cleaned[:4000] if cleaned else "Empty text response."except Exception as e:return f"Error fetching URL '{url}': {str(e)}"42 unmodified lines434445464748497 unmodified lines57585960616263646566676869707172737442 unmodified lines@tooldef fetch_url_text(url: str) -> str:"""Fetches clean plain text from a given URL without repeating or heavy HTML boilerplate.Args:url: The HTTP/HTTPS URL to fetch."""7 unmodified linesheaders={"User-Agent": "Mozilla/5.0"},)response.raise_for_status()raw_html = re.sub(r"(?is)<(script|style|noscript|svg|header|footer|nav).*?>.*?</\1>"," ",response.text,)plain_text = re.sub(r"(?s)<[^>]+>", " ", raw_html)cleaned = re.sub(r"\s+", " ", unescape(plain_text)).strip()if not cleaned:return "Empty text response."if len(cleaned) <= 6000:return cleanedreturn cleaned[:3000] + "\n...\n" + cleaned[-3000:]except Exception as e:return f"Error fetching URL '{url}': {str(e)}"
app.py+11-3