import re import io 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() # Extract body body_match = re.search(r']*>(.*?)', html, re.IGNORECASE | re.DOTALL) content = body_match.group(1) if body_match else html # Remove header/footer content = re.sub(r'', '', content, flags=re.IGNORECASE | re.DOTALL) content = re.sub(r'', '', content, flags=re.IGNORECASE | re.DOTALL) # Also remove script tags at the bottom to avoid conflicts content = re.sub(r'', '', content, flags=re.IGNORECASE | re.DOTALL) # Find swiper-wrappers and replace their content. # Since it's all in one line, we can use regex to find `
...
` inside the swiper. # Wait, this is dangerous because of nested divs. # Instead, since we know there are 5 swipers in the file: # 1. Gallery # 2. Chứng chỉ # 3. Giấy chứng nhận # 4. Quá trình thực hành (xac-nhan-thuc-hanh) # 5. Hình ảnh thực hành (thuc-hanh / training-practical) # A safer approach is to split the content by `
` parts = content.split('
') if len(parts) >= 6: new_content = parts[0] slugs = ['gallery', 'chung-chi', 'giay-chung-nhan', 'xac-nhan-thuc-hanh', 'hinh-anh-thuc-hanh'] for i in range(1, len(parts)): # Find the closing
of the swiper-wrapper. # This is the first
that balances the wrapper, or since we know it's a list of
, # we can just find the end of the last swiper-slide. part = parts[i] # We know each wrapper is closed by
. # But there are nested divs. # A simple hack: look for the end of the last slide which is followed by . # Actually, let's just find the first `` that belongs to the wrapper. # Since the slider items end, the wrapper ends with ``. # Let's count ` 0 and pos < len(part): next_open = part.find('\n" new_content += '
' + replacement + part[pos:] else: new_content = content print("Warning: Did not find exactly 5 swipers. Found", len(parts) - 1) template = f""" Đào tạo tại UMC
{new_content}
""" with open('/home/x79/sisvietnamvn_01/sisvietnamvn_main/src/main/resources/templates/dao-tao.html', 'w', encoding='utf-8') as f: f.write(template) print("Created dao-tao.html successfully!")