From 0e58c37f4e8d83e4f90f424c1ab99d0bf8d35ee3 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:58:35 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E9=85=92=E5=BA=97=E6=BA=90.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/酒店源.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/py/酒店源.py b/py/酒店源.py index 26383d0..e82473c 100644 --- a/py/酒店源.py +++ b/py/酒店源.py @@ -544,18 +544,13 @@ for url in urls: channels = [] for result in results: line = result.strip() - try: - # 尝试分割字符串,如果格式不正确则引发 ValueError - channel_name, channel_url = line.split(',', 1) # 使用逗号分割一次 + if result: + channel_name, channel_url = result.split(',') channels.append((channel_name, channel_url)) - except ValueError: - # 如果发生 ValueError 则打印错误信息并跳过该行 - print(f"跳过无法解析的行: {line}") -# 打开文本文件以追加的形式写入 with open("iptv.txt", 'a', encoding='utf-8') as file: - for channel_name, channel_url in channels: - file.write(f"{channel_name},{channel_url}\n") - print(f"{name},{urld}") #关闭频道名称和频道地址打印,缩短运行时间 + for result in results: + file.write(result + "\n") + print(result) #关闭频道名称和频道地址打印,缩短运行时间 print("频道列表文件iptv.txt追加写入成功!") def remove_duplicates(input_file, output_file):