Update epg下载.py

This commit is contained in:
frxz751113
2025-06-01 13:42:39 +08:00
committed by GitHub
parent cea32e28ce
commit af913d1915
+9 -5
View File
@@ -1,14 +1,18 @@
from urllib.request import Request, urlopen
urls = [
"https://epg.112114.xyz/pp.xml.gz",
"https://epg.pw/xmltv/epg_HK.xml"
"https://epg.112114.xyz/pp.xml.gz", # 第一个文件,扩展名为 .xml.gz
"https://epg.pw/xmltv/epg_HK.xml" # 第二个文件,扩展名为 .xml
]
downloaded_file_name = "pp.xml.gz"
# 遍历URL列表,下载文件
for url in urls:
for i, url in enumerate(urls):
# 根据URL确定文件名和扩展名
if url.endswith('.xml.gz'):
downloaded_file_name = f"file_{i}.xml.gz" # 第一个文件,保持 .xml.gz 扩展名
else:
downloaded_file_name = f"file_{i}.xml" # 第二个文件,保持 .xml 扩展名
try:
req = Request(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'})
with urlopen(req) as response: