python

html_content = f'''<!DOCTYPE html>
<html>
<head>
    <title>HTMLの'<'と'>'をエスケープ</title>
</head>
<body>
    <h1>ともに</h1>
    <p>能登半島</p>
</body>
</html>
'''
# HTML特殊文字をエスケープしてファイルに書き込む
output_file_path = 'escaped_output.txt'
escaped_html_content = html_content.replace('<', '&lt;').replace('>', '&gt;')

with open(output_file_path, 'w') as output_file:
    output_file.write(escaped_html_content)

print(f"HTML content with escaped characters has been saved to {output_file_path}")