Сохранение html страницы в неверной кодировке, в python 3

Всем привет.

Испытываю проблему с сохранением html страниц с записью в файл через python3. А именно часть тэгов на странице которая написана на кириллице отображается в неверной кодировке, при этом если "принтить" (через print) в консоль, то в консоли вывод текста в тэге отображается корректно.

Подскажите пожалуйста в чем проблема может быть? На сайте в мета тэгах явно указана кодировка utf-8 и я при записи файла указываю utf-8.

Гуглить пробовал, подбирал разные варианты с данного сайта, пробовал изменять кодировку при записи в файл, но увы данные варианты мне не помогли.

Мой используемый софт: Windows 10, VScode, Python3

Прикладываю код + скриншоты вывода в консоль и сохранённую html.

Код python:


home_url = 'https://stat.vintem.ru/cabinet/'

headers = {
    'Referer': 'https://vintem.ru/',
    'sec-ch-ua': '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
}

res_home_url = requests.get(home_url, headers=headers, verify=False)
res_home_url.encoding='utf-8'

print(res_home_url.text)

file = open('vintem_LK.html', 'w')
file.write(res_home_url.text)
file.close()

HTML файл:

<html lang=en>

<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<title>������-������� �������� ���������</title>
<link rel=icon type=image/png sizes=32x32 href=./static/img/icons/favicon-32x32.png>
<link rel=icon type=image/png sizes=16x16 href=./static/img/icons/favicon-16x16.png>
<!--[if IE]><link rel="shortcut icon" href="/static/img/icons/favicon.ico"><![endif]-->
<link rel=manifest href=./static/manifest.json><meta name=theme-color content=#4DBA87>
<meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=black><meta name=apple-mobile-web-app-title content=utm5_user_http>
<link rel=apple-touch-icon href=./static/img/icons/apple-touch-icon-152x152.png>
<link rel=mask-icon href=./static/img/icons/safari-pinned-tab.svg color=#4DBA87>
<meta name=msapplication-TileImage content=./static/img/icons/msapplication-icon-144x144.png>
<meta name=msapplication-TileColor content=#000000><link rel=preload href=./static/js/vendor.83b215e50423f51a67bc.js as=script>
<link rel=preload href=./static/js/app.9b71dab96f4f86ae9dca.js as=script>
<link rel=preload href=./static/css/app.c48cd2e9e6eebca82c0ccdba3260b039.css as=style>
<link rel=preload href=./static/js/manifest.3ad1d5771e9b13dbdad2.js as=script>
<link href=./static/css/app.c48cd2e9e6eebca82c0ccdba3260b039.css rel=stylesheet>
</head>

<body>
<noscript>This is your fallback content in case JavaScript fails to load.</noscript>
<div id=app></div>
<script>!function(){"use strict";var o=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
window.addEventListener("load",function(){"serviceWorker"in navigator&&("https:"===window.location.protocol||o)&&navigator.serviceWorker.register("service-worker.js").then(function(o){o.onupdatefound=function()
{if(navigator.serviceWorker.controller){var n=o.installing;n.onstatechange=function(){switch(n.state){case"installed":break;case"redundant":throw new Error("The installing service worker became redundant.")}}}}}).catch(function(o){console.error("Error during service worker registration:",o)})})}();</script>
<script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script>
<script type=text/javascript src=./static/js/vendor.83b215e50423f51a67bc.js></script>
<script type=text/javascript src=./static/js/app.9b71dab96f4f86ae9dca.js></script>
</body>
</html>

Вывод в консоль:

<!DOCTYPE html>
<html lang=en> 

<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<title>ВИНТЕМ-ТЕЛЕКОМ ИНТЕРНЕТ ПРОВАЙДЕР</title>
<link rel=icon type=image/png sizes=32x32 href=./static/img/icons/favicon-32x32.png>
<link rel=icon type=image/png sizes=16x16 href=./static/img/icons/favicon-16x16.png>
<!--[if IE]><link rel="shortcut icon" href="/static/img/icons/favicon.ico"><![endif]-->
<link rel=manifest href=./static/manifest.json><meta name=theme-color content=#4DBA87>
<meta name=apple-mobile-web-app-capable content=yes><meta name=apple-mobile-web-app-status-bar-style content=black><meta name=apple-mobile-web-app-title content=utm5_user_http>
<link rel=apple-touch-icon href=./static/img/icons/apple-touch-icon-152x152.png>
<link rel=mask-icon href=./static/img/icons/safari-pinned-tab.svg color=#4DBA87>
<meta name=msapplication-TileImage content=./static/img/icons/msapplication-icon-144x144.png>
<meta name=msapplication-TileColor content=#000000><link rel=preload href=./static/js/vendor.83b215e50423f51a67bc.js as=script>
<link rel=preload href=./static/js/app.9b71dab96f4f86ae9dca.js as=script>
<link rel=preload href=./static/css/app.c48cd2e9e6eebca82c0ccdba3260b039.css as=style>
<link rel=preload href=./static/js/manifest.3ad1d5771e9b13dbdad2.js as=script>
<link href=./static/css/app.c48cd2e9e6eebca82c0ccdba3260b039.css rel=stylesheet>
</head>

<body>
<noscript>This is your fallback content in case JavaScript fails to load.</noscript>
<div id=app></div>
<script>!function(){"use strict";var o=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
window.addEventListener("load",function(){"serviceWorker"in navigator&&("https:"===window.location.protocol||o)&&navigator.serviceWorker.register("service-worker.js").then(function(o){o.onupdatefound=function()
{if(navigator.serviceWorker.controller){var n=o.installing;n.onstatechange=function(){switch(n.state){case"installed":break;case"redundant":throw new Error("The installing service worker became redundant.")}}}}}).catch(function(o){console.error("Error during service worker registration:",o)})})}();</script>
<script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js></script>
<script type=text/javascript src=./static/js/vendor.83b215e50423f51a67bc.js></script>
<script type=text/javascript src=./static/js/app.9b71dab96f4f86ae9dca.js></script>
</body>
</html>

Ответы (0 шт):