import re with open("tmp_home.html", "r", encoding="utf-8") as f: content = f.read() block8_pattern = re.compile(r'.*?', re.DOTALL) with open("new_block8.html", "r", encoding="utf-8") as f: block8_new = f.read() new_content = block8_pattern.sub(block8_new, content) with open("tmp_home_updated.html", "w", encoding="utf-8") as f: f.write(new_content)