鱼C论坛

 找回密码
 立即注册
查看: 1554|回复: 3

[已解决]求位懂java的大佬看看这个代码

[复制链接]
发表于 2021-9-12 16:27:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. import cn.hutool.http.HttpRequest;
  2. import cn.hutool.http.HttpUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;

  5. /**
  6. * @author ohy
  7. * @date 2021-08-26 09:59:38
  8. **/
  9. public class Test {

  10.     static String cookie ="";

  11.     public static void main(String[] args) {
  12.         String url = "https://drive.kdocs.cn/api/v5/links?offset=0&count=100&orderby=file_mtime&order=DESC&append=false&ignore=link";
  13.         String res = HttpRequest.get(url).header("cookie", cookie).execute().body();
  14.         JSONObject jsonObject = JSONObject.parseObject(res);
  15.         String path = "C:\\Users\\montnets\\Desktop\\test\"
  16.                 + jsonObject.getJSONArray("share").getJSONObject(0).getString("share_name");
  17.         parseGroup(jsonObject.getJSONArray("share").getJSONObject(0).getJSONObject("group").getString("groupid"), path, "0");
  18.     }

  19.     private static void parseGroup(String id, String path, String parentId) {
  20.         String url = "https://drive.kdocs.cn/api/v5/groups/" + id + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30";
  21.         if (!parentId.equals("0")) url += "&parentid=" + parentId;
  22.         String res = HttpRequest.get(url).header("cookie", cookie).execute().body();
  23.         JSONObject jsonObject = JSONObject.parseObject(res);
  24.         JSONArray array = jsonObject.getJSONArray("files");
  25.         for (int i = 0; i < array.size(); i++) {
  26.             JSONObject object = array.getJSONObject(i);
  27.             if (object.getString("ftype").equals("folder")) {
  28.                 String groupId = object.getString("id");
  29.                 String name = object.getString("fname");
  30.                 parseGroup(id, path + "\" + name, groupId);
  31.             } else if (object.getString("ftype").equals("file")) {
  32.                 String fId = object.getString("id");
  33.                 String name = object.getString("fname");
  34.                 String getdownUrl = "https://drive.kdocs.cn/api/v3/groups/" + id + "/files/" + fId + "/download?isblocks=false";
  35.                 res = HttpRequest.get(getdownUrl).header("cookie", cookie).execute().body();
  36.                 String downUrl = JSONObject.parseObject(res).getJSONObject("fileinfo").getString("url");
  37.                 HttpUtil.downloadFile(downUrl, path + "/" + name);
  38.             }
  39.         }
  40.     }
  41. }
复制代码


主要是看不懂java的代码,求大佬帮忙看看能不能给整成python的样式
最佳答案
2021-9-12 16:48:12
  1. url1 = "https://drive.kdocs.cn/api/v5/links?offset=0&count=100&orderby=file_mtime&order=DESC&append=false&ignore=link"
  2. url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
  3. #实例一下
  4. res1  = requests.get(url1)
  5. id_list = res1.json().get('id')
  6. for id in id_list:
  7.     url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
  8.     resp2 = requests.get(url)
  9.     with open(f'{id}',mode='wb',encoding='UTF-8') as file:
  10.        file.write(resp2.content)
  11. 大概意思就是从url1的响应信息(json格式)中拿到id,id有很多个,然后循环的传到url2中,访问url2,下载个什么东东保存到本地
复制代码

注意需要登录
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-9-12 16:48:12 | 显示全部楼层    本楼为最佳答案   
  1. url1 = "https://drive.kdocs.cn/api/v5/links?offset=0&count=100&orderby=file_mtime&order=DESC&append=false&ignore=link"
  2. url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
  3. #实例一下
  4. res1  = requests.get(url1)
  5. id_list = res1.json().get('id')
  6. for id in id_list:
  7.     url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
  8.     resp2 = requests.get(url)
  9.     with open(f'{id}',mode='wb',encoding='UTF-8') as file:
  10.        file.write(resp2.content)
  11. 大概意思就是从url1的响应信息(json格式)中拿到id,id有很多个,然后循环的传到url2中,访问url2,下载个什么东东保存到本地
复制代码

注意需要登录
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-12 17:39:10 | 显示全部楼层

哇  果然换成python就能看懂了  感谢感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-13 11:37:10 | 显示全部楼层
代码要改一下。第5行会报错。返回的结果是列表嵌套字典
url1 = "https://drive.kdocs.cn/api/v5/links?offset=0&count=100&orderby=file_mtime&order=DESC&append=false&ignore=link"
url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
#实例一下
res1  = requests.get(url1)
id_list = res1.json()
for id1 in id_list:
    id1 = id1.get('id')
    url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id1} + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30"
    resp2 = requests.get(url)
    with open(f'{id}',mode='wb',encoding='UTF-8') as file:
       file.write(resp2.content)
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 17:08

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表