File size: 4,408 Bytes
b458f3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
import os

def generate_json_report(data, output_file="report.json"):
    """
    Generates a JSON report of the site analysis.
    """
    try:
        with open(output_file, 'w') as f:
            json.dump(data, f, indent=4)
        print(f"JSON report generated at {os.path.abspath(output_file)}")
    except Exception as e:
        print(f"Error generating JSON report: {e}")

def generate_html_report(data, output_file="report.html"):
    """
    Generates an HTML report for the domain scan.
    """
    summary = data['summary']
    details = data['details']

    html = f"""
    <!DOCTYPE html>
    <html>
    <head>
        <title>SEO Image Alt Text Report</title>
        <style>
            body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 20px; background-color: #f4f6f9; }}
            h1, h2 {{ color: #333; }}
            .container {{ max-width: 1200px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
            .summary-box {{ display: flex; gap: 20px; margin-bottom: 30px; }}
            .card {{ flex: 1; padding: 20px; border-radius: 8px; color: white; text-align: center; }}
            .bg-blue {{ background-color: #007bff; }}
            .bg-green {{ background-color: #28a745; }}
            .bg-red {{ background-color: #dc3545; }}
            .card h3 {{ margin: 0; font-size: 3em; }}
            .card p {{ margin: 0; opacity: 0.9; }}
            
            table {{ border-collapse: collapse; width: 100%; margin-top: 10px; }}
            th, td {{ border: 1px solid #dee2e6; padding: 12px; text-align: left; }}
            th {{ background-color: #f8f9fa; color: #495057; }}
            tr:nth-child(even) {{ background-color: #f9f9f9; }}
            .page-section {{ margin-bottom: 40px; border-top: 2px solid #eee; padding-top: 20px; }}
            .page-url {{ font-size: 1.2em; font-weight: bold; color: #0056b3; margin-bottom: 10px; display: block; }}
            .no-issues {{ color: #28a745; font-style: italic; }}
            .img-link {{ word-break: break-all; color: #555; }}
        </style>
    </head>
    <body>
    <div class="container">
        <h1>SEO Image Alt Text Report</h1>
        
        <div class="summary-box">
            <div class="card bg-blue">
                <h3>{summary['total_pages_scanned']}</h3>
                <p>Pages Scanned</p>
            </div>
            <div class="card bg-green">
                <h3>{summary['total_images_found']}</h3>
                <p>Total Images Found</p>
            </div>
            <div class="card bg-red">
                <h3>{summary['total_images_missing_alt']}</h3>
                <p>Images Missing Alt Text</p>
            </div>
        </div>
    """

    if summary.get('crawl_blocked'):
        html += f"""
        <div style="background-color: #fff3cd; color: #856404; padding: 15px; border: 1px solid #ffeeba; border-radius: 5px; margin-bottom: 20px;">
            <strong>⚠️ CRAWL BLOCKED:</strong> The crawler was blocked by the site ({summary.get('blocked_reason')}). Results are likely incomplete.
            <p>Try using a residential proxy or a headless browser with stealth plugins to bypass this restriction.</p>
        </div>
        """
    
    html += """
        <h2>Detailed Breakdown</h2>
    """

    if not details:
        html += "<p class='no-issues'>No pages found with missing alt text images! Great job.</p>"
    
    for page in details:
        html += f"""
        <div class="page-section">
            <a href="{page['page_url']}" class="page-url" target="_blank">Page: {page['page_url']}</a>
            <p><strong>{page['missing_alt_count']}</strong> images missing alt text</p>
            <table>
                <tr><th>Image Source URL</th></tr>
        """
        for img_src in page['images_without_alt']:
            html += f"""
                <tr>
                    <td><a href="{img_src}" target="_blank" class="img-link">{img_src}</a></td>
                </tr>
            """
        html += "</table></div>"

    html += """
    </div>
    </body>
    </html>
    """
    
    try:
        with open(output_file, 'w') as f:
            f.write(html)
        print(f"HTML report generated at {os.path.abspath(output_file)}")
    except Exception as e:
        print(f"Error generating HTML report: {e}")