changed encoding showup

This commit is contained in:
2025-03-04 00:05:03 +03:00
parent e19d44e4b1
commit 6af9d23ee7

View File

@@ -27,8 +27,10 @@ def init_proxy(app):
# Получаем ленту
proxies = {"http": PROXY_URL, "https": PROXY_URL} if PROXY_URL else None
r = requests.get(url, timeout=10, proxies=proxies)
r.encoding = "windows-1251" if "windows-1251" in r.headers.get("content-type", "").lower() else r.apparent_encoding
xml_data = r.text.replace('<?xml version="1.0" encoding="windows-1251"?>', '<?xml version="1.0" encoding="UTF-8"?>')
_encode = r.apparent_encoding.lower()
r.encoding = _encode
xml_data = r.text.replace(f'<?xml version="1.0" encoding="{_encode}"?>',
'<?xml version="1.0" encoding="UTF-8"?>')
# Разбираем XML
root = ET.fromstring(xml_data)