-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_scrapper.py
35 lines (27 loc) · 1.1 KB
/
web_scrapper.py
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
28
29
30
31
32
33
34
35
# Simple Python program for a basic web scraper
#Before running the code, make sure to install the required libraries using:
#pip install beautifulsoup4 requests
#Once installed, you can run the script and provide the URL of a website you'd like to scrape.
import requests
from bs4 import BeautifulSoup
def web_scraper():
print("Enter the URL of the website to scrape:")
url = input()
try:
# Make an HTTP request to the specified URL
response = requests.get(url)
response.raise_for_status()
# Parse the HTML content of the page
soup = BeautifulSoup(response.text, 'html.parser')
# Extract and display information
print(f"\nFetching data from {url}...\n")
print(f"Extracted Information:")
print(f"- Title: {soup.title.string}")
paragraphs = soup.find_all('p')
print("- Paragraphs:")
for i, paragraph in enumerate(paragraphs, 1):
print(f" {i}. {paragraph.get_text()}")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
if __name__ == "__main__":
web_scraper()