"""Glassdoor site preset."""
import re

class Glassdoor:
    """Extract structured data from glassdoor.com pages."""
    
    DOMAINS = ["glassdoor.com", "www.glassdoor.com"]
    
    @staticmethod
    def extract(url, html):
        """Extract page data from HTML."""
        data = {"url": url, "site": "glassdoor"}
        
        # Title
        m = re.search(r'<title[^>]*>([^<]+)</title>', html, re.I)
        if m:
            data["title"] = m.group(1).strip()
        
        # Meta description
        m = re.search(r'<meta[^>]*name=["\']description["\'][^>]*content=["\'](.*?)["\']', html, re.I)
        if m:
            data["description"] = m.group(1).strip()
        
        # H1
        m = re.search(r'<h1[^>]*>(.*?)</h1>', html, re.I | re.S)
        if m:
            data["heading"] = re.sub(r'<[^>]+>', '', m.group(1)).strip()
        
        # Images
        images = re.findall(r'<img[^>]*src=["\'](https?://[^"\']+)["\']', html, re.I)
        if images:
            data["images"] = images[:10]
        
        # Links
        links = re.findall(r'<a[^>]*href=["\'](https?://[^"\']+)["\'][^>]*>(.*?)</a>', html, re.I | re.S)
        if links:
            data["links"] = [{"url": u, "text": re.sub(r'<[^>]+>', '', t).strip()} for u, t in links[:20]]
        
        return data
