# --*-- coding:utf-8 --*--
import os
import shutil
from lxml import etree
path = "/Users/rouckiechen/Desktop/china_court_result/guojia"
dst_path = "/Users/rouckiechen/Desktop/china_court_result/unknown_doc/guojia"
doc_list = os.listdir(path)
for i in doc_list:
if i.startswith('.'): # 删除.开头的文件
os.remove(path + "/" + i)
with open(path + "/" + i, encoding="utf-8") as f: # 移除暂未提取到标题的文件
text = f.read()
html = etree.HTML(text)
title_1 = "".join(html.xpath(r'//font[@class="MTitle"]/text()')).strip()
title_2 = "".join(html.xpath(r'//div[@class="content_text"]/p[1]/strong/text()')).strip()
title = title_1 if title_1 else title_2
if not title:
print("没标题", i)
shutil.move(path + "/" + i, dst_path)
count = len(doc_list) # 简单统计文件数目
print(count)