代码拉取完成,页面将自动刷新
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# SETP3 : 导出md的表格
import requests
import json
import urllib
import os
export = "|序号|图片|标题|单词数量|文件大小|背诵人数|下载地址|id|标签|\n";
export = export + "|---|---|---|---|---|---|---|---|---|\n";
def getTag( tag ):
result = [];
for i in tag:
result.append(i["tagName"]);
return "、".join(result);
with open("./bookLists.txt",'r',encoding='UTF-8') as load_f:
load_dict = json.load(load_f)
bookLists = load_dict['data']['normalBooksInfo']
bookLen = len(bookLists);
nowIndex = 0;
for i in bookLists:
nowIndex = nowIndex +1;
id = i['id']
picUrl = i['cover']
title = i['title']
wordNum = i['wordNum']
fizeSize = i['size']
reciteUserNum = i['reciteUserNum']
fileUrl = i['offlinedata'];
# tag = "";
tag = getTag(i['tags']);
filename = os.path.basename(fileUrl)
basefile = "book/";
picMD = "![{}]({})".format(title,picUrl);
downloadUrl = "[{}]({}{}) [{}]({})".format( "本地地址",basefile,filename, "原始地址",fileUrl,);
item = "|{}|{}|{}|{}|{}|{}|{}|{}|{}|\n".format(nowIndex,picMD,title,wordNum,fizeSize,reciteUserNum,downloadUrl,id,tag)
export = export + item;
print( export )
with open("./export.txt",'w',encoding='UTF-8') as f:
f.write( export );
f.close
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。