Spaces:
Build error
Build error
Create scraper.py
Browse files- scraper.py +11 -0
scraper.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
|
| 4 |
+
def scrape_website(url):
|
| 5 |
+
try:
|
| 6 |
+
response = requests.get(url)
|
| 7 |
+
response.raise_for_status()
|
| 8 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 9 |
+
return soup.get_text(separator=' ')
|
| 10 |
+
except Exception as e:
|
| 11 |
+
return f"Error: Unable to scrape the website. Details: {e}"
|