SEO tool

 

import requests from bs4 import BeautifulSoup def analyze_meta_tags(url): try: # Fetch the HTML content of the URL response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # Extract meta tags meta_tags = soup.find_all('meta') meta_data = {} for tag in meta_tags: if tag.get('name'): meta_data[tag.get('name').lower()] = tag.get('content') elif tag.get('property'): meta_data[tag.get('property').lower()] = tag.get('content') # Analyze meta tags meta_title = meta_data.get('title', '') meta_description = meta_data.get('description', '') meta_keywords = meta_data.get('keywords', '') meta_title_length = len(meta_title) meta_description_length = len(meta_description) keywords_list = meta_keywords.split(',') if meta_keywords else [] total_words = sum(len(word.split()) for word in keywords_list) keyword_density = total_words / max(1, len(meta_title.split()) + len(meta_description.split())) # Print analysis print(f"Meta Title: {meta_title}") print(f"Meta Description: {meta_description}") print(f"Meta Keywords: {meta_keywords}") print(f"Meta Title Length: {meta_title_length} characters") print(f"Meta Description Length: {meta_description_length} characters") print(f"Keyword Density: {keyword_density:.2f}") except Exception as e: print("An error occurred:", e) # Example usage url = input("Enter the URL of your blog post: ") analyze_meta_tags(url)

Post a Comment

0 Comments