123456789101112131415161718192021 |
- # 输入文件,包含URL的内容
- input_file = 'extracted_urls1.txt'
- # 输出文件,用于存放去重后的URL
- output_file = 'unique_urls1.txt'
- # 存放URL的集合
- urls_set = set()
- # 读取输入文件中的URL并去除重复项
- with open(input_file, 'r') as file:
- for line in file:
- urls_set.add(line.strip())
- # 将去重后的URL写入输出文件
- with open(output_file, 'w') as file:
- for url in urls_set:
- # 每个URL单独一行
- file.write(url + '\n')
- print("去除重复的URL并保存到输出文件中。")
|