DEV Community

Dylan Parker
Dylan Parker

Posted on

I needed to generate hundreds of meta descriptions for a client's e-commerce site.

Instead of writing them manually, I wrote a Python script that uses a simple keyword extraction method to pull key terms from product descriptions and combine them into a template. Here's a snippet:

python
import re
from collections import Counter

def extract_keywords(text, top_n=5):
words = re.findall(r'\b[a-z]{3,}\b', text.lower())
return [word for word, _ in Counter(words).most_common(top_n)]

def generate_meta(description):
keywords = extract_keywords(description)
return f"Shop our {', '.join(keywords[:3])} collection. {description[:100]}..."

It's not perfect, but it saves a ton of time. For more complex SEO tasks, I've been using a tool that automates keyword research and meta tag generation. What's your workflow for bulk meta descriptions?

Top comments (0)