Update 酒店源.py

This commit is contained in:
frxz751113
2024-09-01 00:58:35 +08:00
committed by GitHub
parent 2f43c996f9
commit 0e58c37f4e
+5 -10
View File
@@ -544,18 +544,13 @@ for url in urls:
channels = [] channels = []
for result in results: for result in results:
line = result.strip() line = result.strip()
try: if result:
# 尝试分割字符串,如果格式不正确则引发 ValueError channel_name, channel_url = result.split(',')
channel_name, channel_url = line.split(',', 1) # 使用逗号分割一次
channels.append((channel_name, channel_url)) channels.append((channel_name, channel_url))
except ValueError:
# 如果发生 ValueError 则打印错误信息并跳过该行
print(f"跳过无法解析的行: {line}")
# 打开文本文件以追加的形式写入
with open("iptv.txt", 'a', encoding='utf-8') as file: with open("iptv.txt", 'a', encoding='utf-8') as file:
for channel_name, channel_url in channels: for result in results:
file.write(f"{channel_name},{channel_url}\n") file.write(result + "\n")
print(f"{name},{urld}") #关闭频道名称和频道地址打印,缩短运行时间 print(result) #关闭频道名称和频道地址打印,缩短运行时间
print("频道列表文件iptv.txt追加写入成功!") print("频道列表文件iptv.txt追加写入成功!")
def remove_duplicates(input_file, output_file): def remove_duplicates(input_file, output_file):