Files
sisvietnamvn_01/.temp/parse_html.py
T

22 lines
944 B
Python

import re
import json
with open('/home/x79/sisvietnamvn_01/sisvietnamvn_Trang chính thức hiện tại/Đào tạo tại UMC.html', 'r', encoding='utf-8') as f:
html = f.read()
# Try to extract the main content. It's usually inside <div id="content"> or <main>
# Looking at typical Tailwind pages, let's extract everything inside <body> </body>
body_match = re.search(r'<body[^>]*>(.*)</body>', html, re.IGNORECASE | re.DOTALL)
if body_match:
content = body_match.group(1)
else:
content = html
# We know there are 4 Swiper instances. Let's find them.
# A swiper usually has `<div class="swiper swiper-initialized ..."> ... </div>`
# It's a bit tricky to parse nested divs with regex.
# Let's extract the slider images using regex on `swiper-slide`
slides = re.findall(r'<div class="swiper-slide[^>]*>.*?<img[^>]*src="([^"]+)"[^>]*>.*?</div>', html, re.IGNORECASE | re.DOTALL)
print(f"Found {len(slides)} slides with images.")