
import requests
from bs4 import BeautifulSoup
# Function to perform on-page SEO analysis
def analyze_seo(www.studioyamson.com, target_keyword):
try:
# Send an HTTP GET request to the URL
response = requests.get(url)
if response.status_code == 200:
# Parse the HTML content of the page using BeautifulSoup
soup = BeautifulSoup(response.text, 'html.parser')
# Extract page title
page_title = soup.title.string if soup.title else "No title tag found"
# Extract meta description
meta_description = ""
meta_tag = soup.find('meta', attrs={'name': 'description'})
if meta_tag:
meta_description = meta_tag.get('content')
# Check if the keyword appears in the title
keyword_in_title = target_keyword.lower() in page_title.lower()
# Check if the keyword appears in the meta description
keyword_in_meta_description = target_keyword.lower() in meta_description.lower()
# Check if the keyword appears in headers
header_tags = soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])
keyword_in_headers = any(target_keyword.lower() in tag.get_text().lower() for tag in header_tags)
# Print the analysis results
print(f"URL: {url}")
print(f"Page Title: {page_title}")
print(f"Meta Description: {meta_description}")
print(f"Keyword in Title: {keyword_in_title}")
print(f"Keyword in Meta Description: {keyword_in_meta_description}")
print(f"Keyword in Headers: {keyword_in_headers}")
else:
print(f"Failed to fetch URL. Status Code: {response.status_code}")
except Exception as e:
print(f"An error occurred: {str(e)}")
# Example usage
if __name__ == "__main__":
website_url = "https://www.studioyamson.com"
target_keyword = "music producer" # Updated target keyword
analyze_seo(website_url, target_keyword)