import requests
import time
resp=requests.get('https://dushu.baidu.com/api/pc/getCatalog?data={%22book_id%22:%224306063500%22}')
dic_data=resp.json()
item_list=dic_data['data']['novel']['items']
url='https://dushu.baidu.com/api/pc/getChapterContent?data={"book_id":"4306063500","cid":"4306063500|'
for index,item in enumerate(item_list):
cid=item['cid']
baseUrl=url+cid+'"}'
resp1=requests.get(baseUrl)
novel_text=resp1.json()
novel=novel_text['data']['novel']['content']
title=item['title']
print(novel)
with open('novel/'+title+'.txt','w',encoding='utf-8') as novel_writer:
novel_writer.write(novel)
time.sleep(5)