|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import cn.hutool.http.HttpRequest;
- import cn.hutool.http.HttpUtil;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- /**
- * @author ohy
- * @date 2021-08-26 09:59:38
- **/
- public class Test {
- static String cookie ="";
- public static void main(String[] args) {
- String url = "https://drive.kdocs.cn/api/v5/links?offset=0&count=100&orderby=file_mtime&order=DESC&append=false&ignore=link";
- String res = HttpRequest.get(url).header("cookie", cookie).execute().body();
- JSONObject jsonObject = JSONObject.parseObject(res);
- String path = "C:\\Users\\montnets\\Desktop\\test\"
- + jsonObject.getJSONArray("share").getJSONObject(0).getString("share_name");
- parseGroup(jsonObject.getJSONArray("share").getJSONObject(0).getJSONObject("group").getString("groupid"), path, "0");
- }
- private static void parseGroup(String id, String path, String parentId) {
- String url = "https://drive.kdocs.cn/api/v5/groups/" + id + "/files?linkgroup=true&include=acl,pic_thumbnail&offset=0&count=30";
- if (!parentId.equals("0")) url += "&parentid=" + parentId;
- String res = HttpRequest.get(url).header("cookie", cookie).execute().body();
- JSONObject jsonObject = JSONObject.parseObject(res);
- JSONArray array = jsonObject.getJSONArray("files");
- for (int i = 0; i < array.size(); i++) {
- JSONObject object = array.getJSONObject(i);
- if (object.getString("ftype").equals("folder")) {
- String groupId = object.getString("id");
- String name = object.getString("fname");
- parseGroup(id, path + "\" + name, groupId);
- } else if (object.getString("ftype").equals("file")) {
- String fId = object.getString("id");
- String name = object.getString("fname");
- String getdownUrl = "https://drive.kdocs.cn/api/v3/groups/" + id + "/files/" + fId + "/download?isblocks=false";
- res = HttpRequest.get(getdownUrl).header("cookie", cookie).execute().body();
- String downUrl = JSONObject.parseObject(res).getJSONObject("fileinfo").getString("url");
- HttpUtil.downloadFile(downUrl, path + "/" + name);
- }
- }
- }
- }
复制代码
主要是看不懂java的代码,求大佬帮忙看看能不能给整成python的样式
- 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().get('id')
- for id in id_list:
- url2 = f"https://drive.kdocs.cn/api/v5/groups/" + {id} + "/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)
- 大概意思就是从url1的响应信息(json格式)中拿到id,id有很多个,然后循环的传到url2中,访问url2,下载个什么东东保存到本地
复制代码
注意需要登录
|
|