# -*- coding: utf-8 -*- """对 index.html 做硬性约束的自动化校验""" import re, sys with open('/data/workspace/index.html', 'r', encoding='utf-8') as f: html = f.read() results = [] def check(name, cond): results.append((name, bool(cond))) # 1. 无表单/输入/用户输入模块 check("1. 无表单/输入框(禁止用户输入模块)", not re.search(r'(.*?)', html, re.S) title_txt = title_m.group(1) if title_m else '' check("3a. title 三要素非空", len(title_txt.strip()) > 10) check("3b. title 含更新时间(格式: 更新时间:xxxx-xx-xx xx:xx:ss)", bool(re.search(r'更新时间:\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}', title_txt))) # keywords / description check("3c. keywords 非空", bool(re.search(r'name="keywords"\s+content="[^"]+', html))) check("3d. description 非空", bool(re.search(r'name="description"\s+content="[^"]+', html))) # 4. 广告法:禁止绝对化用语 banned = ['最好','最佳','第一','顶级','全网最优','最专业','独一无二','绝对','极致','最'] found_banned = [w for w in banned if w in html] check("4. 无绝对化用语(最/第一/顶级等): %s" % (found_banned if found_banned else 'OK',), len(found_banned) == 0) # 5. 导航在7个宽度下单行 + 移动端折叠 # 1920 = 桌面默认基线(默认 .nav-menu a 单行样式);1440/1280/1100/1024/768/375 为显式媒体查询断点 check("5. 1920px 桌面基线(默认导航单行样式)", bool(re.search(r'\.nav-menu\s+a\s*\{[^}]*white-space:\s*nowrap', html, re.S))) for bp in [1440, 1280, 1100, 1024, 768, 375]: check("5. 媒体查询断点 %dpx 已定义" % bp, '@media (max-width:%dpx)' % bp in html) check("5. 移动端折叠菜单(nav-toggle / .open)", '.nav-toggle' in html and '.nav-menu.open' in html) # 6. 资质证书模块:未提供素材 -> 不应出现资质证书板块 check("6. 无资质证书模块代码(未提供素材)", '资质证书' not in html) # 7. 底部无 ICP 备案信息 check("7. 底部无ICP备案信息", not re.search(r'ICP|备案号|京ICP|公网安备', html)) # 8. 图片:使用提供的链接,无叠加文字/水印标签(检查img标签无文字叠加结构) imgs = re.findall(r']+src="([^"]+)"', html) provided = [ 'Image260914191113368ddf.jpg','Image260914191114571376.jpg', 'Image26091419111369669b.jpg','Image26091419111430694a.jpg', 'Image2609141911147744c1.jpg','Image260914191115290ce8.jpg', 'Image260914191115571fee.jpg','Image260914191115993315.jpg', 'Image260916150037846614.png','Image26091614584183361d.png', ] all_provided = all(any(p in s for p in provided) for s in imgs) check("8a. 所有img均为提供的链接(无外部/生成图片)", all_provided and len(imgs) > 0) check("8b. Banner图使用指定png(1920x1000)", 'Image260916150037846614.png' in html) check("8c. 关于我们配图使用指定png", 'Image26091614584183361d.png' in html) # 无叠加文字:img 不在含绝对定位文字的包裹层(这里简单检查没有 watermark/text-overlay 类) check("8d. 图片无叠加水印/标签结构", not re.search(r'watermark|img-text|img-label|overlay-text', html, re.I)) # 9. 板块完整性 for sec in ['首页Banner','产品展示','关于我们','应用场景','合作案例','售后服务','常见问题FAQ','城市分站','友情链接']: key = {'首页Banner':'banner'}.get(sec, None) check("9. 板块完整(产品/关于/场景/案例/售后/FAQ/分站/链接)", all(k in html for k in ['id="products"','id="about"','id="scenes"','id="cases"','id="service"','id="faq"','id="city"','id="links"'])) # 输出 ok = 0 for name, cond in results: print(('✅ ' if cond else '❌ ') + name) if cond: ok += 1 print('\n通过: %d / %d' % (ok, len(results))) sys.exit(0 if ok == len(results) else 1)