Scaper_search / scraper.py
gaur3009's picture
Rename # scraper.py to scraper.py
a6278d1 verified
raw
history blame
384 Bytes
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}]"