from hanlp_restful import HanLPClient
with open(“book.txt”,‘r’,encoding=‘utf-8’) as f:
book=f.read()
HanLP = HanLPClient(‘https://www.hanlp.com/api’,auth=‘API密钥’,language='zh’) # auth需要申请
doc = HanLP.tokenize(book) #进行分词
with open(“renci.txt”,‘w’) as f:
f.writelines(str(doc).strip())