-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-web_scraper.py
More file actions
29 lines (23 loc) · 946 Bytes
/
Copy pathbasic-web_scraper.py
File metadata and controls
29 lines (23 loc) · 946 Bytes
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
# BASIC WEB SCRAPER
'''Description: A program that fetches and displays the current weather of a specified location using API.'''
#code for basic web scraper
import requests
from bs4 import BeautifulSoup
def basic_web_scraper(url):
# Send a GET request to the URL
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Example: Extract all the links from the page
links = soup.find_all('a')
# Print all the links
for link in links:
print(link.get('href'))
else:
print(f"Failed to retrieve content, status code {response.status_code}")
if __name__ == "__main__":
# URL of the webpage to scrape
url = input("enter the url:")
basic_web_scraper(url)