import requests
from bs4 import BeautifulSoup
url = 'https://example.com'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Extract title tag
title_tag = soup.title
print(f"Title: {title_tag.string if title_tag else 'N/A'}")
# Extract meta description
meta_desc = soup.find('meta', attrs={'name': 'description'})
print(f"Description: {meta_desc['content'] if meta_desc else 'N/A'}")
If you're a developer looking to automate SEO tasks, you've probably encountered the time-consuming nature of manual analysis. SEO is a critical part of digital marketing, but it's often tedious to check each website's metadata, headings, and other elements. That's where automation comes in. With a simple Python script, you can analyze multiple websites in seconds and generate clean, actionable reports.
The script above demonstrates how to extract title and meta description tags from a single website. These are two of the most important SEO elements, and having them in place can significantly impact search engine rankings. But SEO analysis goes beyond just metadata. It includes checking for broken links, page speed, meta tags, heading structure, and more.
To make this process efficient, I've created a full Python script that automates SEO analysis in just 30 seconds. This tool is designed for developers who want to integrate SEO checks into their marketing workflows. It requires no setup and includes complete source code, so you can use it forever without any restrictions.
Here's a snippet of the full script that performs a basic SEO analysis:
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
from collections import defaultdict
def analyze_seo(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# Extract title
title = soup.title.string if soup.title else 'N/A'
# Extract meta description
meta_desc = soup.find('meta', attrs={'name': 'description'})
description = meta_desc['content'] if meta_desc else 'N/A'
# Extract heading tags
headings = defaultdict(int)
for tag in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']):
headings[tag.name] += 1
# Extract internal links
internal_links = set()
for link in soup.find_all('a', href=True):
href = urljoin(url, link['href'])
if href.startswith(url):
internal_links.add(href)
return {
'title': title,
'description': description,
'headings': dict(headings),
'internal_links': list(internal_links)
}
# Example usage
results = analyze_seo('https://example.com')
print(results)
This script provides a clean and actionable output, making it easy to integrate into larger workflows. It checks for title and description tags, counts heading tags, and identifies internal links. You can expand this script to include additional SEO metrics like broken links, page speed, or content quality checks.
If you're looking for a ready-to-use solution that saves you 10 hours a week on SEO tasks, consider the SEO Analysis Tool. It includes a full Python script that automates all the tasks mentioned above and more. The tool is designed for developers who want to streamline their marketing workflows and focus on higher-value tasks.
In summary, automation is a game-changer for SEO analysis. By using Python scripts, you can save time, reduce errors, and focus on what truly matters—improving your website's performance and visibility. Whether you're building a productivity tool or automating marketing workflows, the right script can make all the difference. Start by analyzing your website's SEO with a few lines of Python and take control of your digital marketing strategy.
Top comments (0)