From 4a48de2052d807d012755e8ec97741c194995d92 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:31:27 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E7=BD=91=E7=BB=9C=E6=94=B6=E9=9B=86.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/网络收集.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/py/网络收集.py b/py/网络收集.py index 187d5a5..4a0db76 100644 --- a/py/网络收集.py +++ b/py/网络收集.py @@ -347,29 +347,29 @@ import os # 定义一个包含所有要排除的关键词的列表 excluded_keywords = [ 'epg', 'mitv', 'udp', 'rtp', 'P2p', 'p2p', 'p3p', 'P2P', '新闻综合', 'P3p', 'jdshipin', '9930/qilu', 'gitcode.net', '151:99', '21dtv', '8.137', 'txmov2', 'gcw.bdcdn', 'metshop', - 'shandong', 'goodiptv', '购物', '[', 'P3P', '腔', '曲', '//1', '/hls/', '春节', 'free', 'ts138', 'hlspull', '95.179', 'gat' + 'shandong', 'goodiptv', '购物', '[', 'P3P', '腔', '曲', '//1', '/hls/', '春节', 'free', 'ts138', 'hlspull', '95.179', 'gat', 'ali' # 在这里添加需要排除的关键词 ] # 定义一个包含所有要提取的关键词的列表 extract_keywords = ['1905', '凤凰卫视', '人间卫视', '亚洲卫视', '香港卫视', '神乐', '翡翠台', '凤凰香港', '凤凰中文', '凤凰资讯', 'AXN', 'AMC', '香蕉', '电影台', '大爱', '东森', 'MTV', '华视', '中天', '天良', '翡翠台', '美亚', '星影', '纬来', '天映', '无线', '华剧台', '华丽台', '剧台', 'Movie', '八大', '采昌', '靖天', '美亚', '民視', '探索', '旅游', '影视2', - '影视3', '中视', '豬哥亮', 'TVB', '东森', '公视', '华视', '寰宇', '戏剧', '靖', '龙华', '龙祥', '民视', '三立', '中视', '猪哥亮', '综艺', '新闻', '影迷', '影剧', '电视剧', 'ali' + '影视3', '中视', '豬哥亮', 'TVB', '东森', '公视', '华视', '寰宇', '戏剧', '靖', '龙华', '龙祥', '民视', '三立', '中视', '猪哥亮', '综艺', '新闻', '影迷', '影剧', '电视剧' # 在这里添加需要提取的关键词 ] # 读取文件并处理每一行 +import re with open('2.txt', 'r', encoding='utf-8') as file: lines = file.readlines() - # 创建或打开一个输出文件用于写入处理后的数据 - with open('2.txt', 'w', encoding='utf-8') as outfile: - for line in lines: - # 首先检查行是否包含任何提取关键词 - if any(keyword in line for keyword in extract_keywords): - # 如果包含提取关键词,进一步检查行是否不包含任何排除关键词 - if not any(keyword in line for keyword in excluded_keywords): - outfile.write(line) # 写入符合条件的行到文件 +with open('2.txt', 'w', encoding='utf-8') as outfile: + for line in lines: + cleaned_line = re.sub(r'[^\w\s]', '', line) + lower_cleaned_line = cleaned_line.lower() + if any(keyword in lower_cleaned_line for keyword in extract_keywords): + if not any(keyword in lower_cleaned_line for keyword in [excluded_key.lower() for excluded_key in excluded_keywords]): + outfile.write(line) ###############################################################