-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitignore
More file actions
38 lines (30 loc) · 1.18 KB
/
.gitignore
File metadata and controls
38 lines (30 loc) · 1.18 KB
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
36
37
#This works just have the module beautifulsoup4 installed
import requests
from bs4 import BeautifulSoup
import time
def analyze_website(url):
try:
start = time.time()
response = requests.get(url)
load_time = time.time() - start
if response.status_code != 200:
print(f"Failed to retrieve {url}: Status code {response.status_code}")
return
soup = BeautifulSoup(response.text, 'html.parser')
title = soup.title.string if soup.title else 'No title found'
num_links = len(soup.find_all('a'))
num_images = len(soup.find_all('img'))
word_count = len(soup.get_text().split())
print(f"--- Analysis of {url} ---")
print(f"Status Code: {response.status_code}")
print(f"Title: {title}")
print(f"Load Time: {load_time:.2f} seconds")
print(f"Number of Links: {num_links}")
print(f"Number of Images: {num_images}")
print(f"Total Words on Page: {word_count}")
except Exception as e:
print(f"Error analyzing {url}: {e}")
# Example usage
if __name__ == "__main__":
url = input("Enter a website URL (with https://): ")
analyze_website(url)