#!/usr/bin/python
# -*- coding: UTF-8 -*-
list1=[] # 最終列表
b=None
with open(r"D:\Desktop\bookmarks.html",'r',encoding='utf-8') as fh:
? ? for line in fh:
? ? ? ? # print(line.strip())
? ? ? ? # print(type(line))
? ? ? ? # print(line.split())
? ? ? ? f=line.strip()
? ? ? ? a=f.split('>')
? ? ? ? if len(a) <3: # 切片后長度小于3就是普通標簽直接添加,否則就是收藏夾要去重復
? ? ? ? ? ? list1.append(f)
? ? ? ? elif a[-2] != b:
? ? ? ? ? ? list1.append(f)
? ? ? ? ? ? b = a[-2]
? ? ? ? ? ? # print(b)
with open(r"d:\Desktop\new_html.html",'w',encoding='utf-8') as f:
? ? for i in list1:
? ? ? ? f.write(i)
? ? ? ? f.write('\n')