大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇内容主要讲解“如何用python获取网盘数据”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何用python获取网盘数据”吧!
沾化网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联于2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联。
随着版权越来越重,做个电影站、磁力站、小说站已经越来越难,而网盘搜索的话由于背靠百度大哥,还相对好一些,但是百度压力也是越来越大,这个领域获取数据其实也基本不太可能。好在有些团队凭借着长期的数据储备,积累了很多相关数据,可以采用直接调用数据的形式实现,目前做的比较好的当属小葱计算,这是小编最近才发现的一个平台,也大概看了下demo,确实很容易,以python为例:
# -*- coding: utf-8 -*- # flake8: noqa __author__ = 'wukong' import urllib from urllib import urlencode #配置您申请的appKey和openId app_key="***" open_id="***" """ request_url 请求地址 params 请求参数 method 请求方法 """ def request_content(request_url,params,method): params = urlencode(params) if method and method.lower() =="get": f = urllib.urlopen("%s?%s" % (request_url, params)) else: f = urllib.urlopen(request_url, params) content = f.read() print content def main(): domain="http://api.xiaocongjisuan.com/" servlet="data/skydriverdata/get" method="get" request_url=domain+servlet #字典 params ={} params["appKey"]=app_key params["openId"]=open_id #变动部分 params["q"]="a" params["currentPage"]=1 params["pageSize"]=20 request_content(request_url,params,method) if __name__ == '__main__': main()
java 为例:
package com.xiaocongjisuan.module.example; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; public class Application { public static final String DEF_CHATSET = "UTF-8"; public static final int DEF_CONN_TIMEOUT = 30000; public static final int DEF_READ_TIMEOUT = 30000; public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"; //配置您申请的appKey和openId public static final String APP_KEY ="yours"; public static final String OPEN_ID ="yours"; //将map型转为请求参数型 public static String urlEncode(Mapparams) { if(params==null){return "";}; StringBuilder sb = new StringBuilder(); for (Map.Entry i : params.entrySet()) { try { sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } String r=sb.toString(); if(r.endsWith("&")){ r = r.substring(0,r.length()-1); } return r; } /** * * @param requestUrl 请求地址 * @param params 请求参数 * @param method 请求方法 * @return 请求结果 * @throws Exception */ public static String requestContent(String requestUrl, Map params,String method) throws Exception { HttpURLConnection conn = null; BufferedReader reader = null; String rs = null; try { //组装请求链接 StringBuffer sb = new StringBuffer(); if(method!=null&&method.equalsIgnoreCase("get")){ requestUrl = requestUrl+"?"+urlEncode(params); } //默认get URL url = new URL(requestUrl); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); if(method!=null&&method.equalsIgnoreCase("post")){ conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); } //参数配置 conn.setRequestProperty("User-agent", userAgent); conn.setUseCaches(false); conn.setConnectTimeout(DEF_CONN_TIMEOUT); conn.setReadTimeout(DEF_READ_TIMEOUT); conn.setInstanceFollowRedirects(false); conn.connect(); if (params!= null && method.equalsIgnoreCase("post")) { try { DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(urlEncode(params)); } catch (Exception e) { e.printStackTrace(); } } //读取数据 InputStream is = conn.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET)); String strRead = null; while ((strRead = reader.readLine()) != null) { sb.append(strRead); } rs = sb.toString(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { reader.close(); } if (conn != null) { conn.disconnect(); } } return rs; } public static void main(String[] args) throws Exception{ String domain="http://api.xiaocongjisuan.com/"; String servlet="data/skydriverdata/get"; String method="get"; String requestUrl=domain+servlet; Map params=new HashMap (); params.put("appKey",APP_KEY); params.put("openId",OPEN_ID); //变动部分 params.put("q","a"); params.put("currentPage",1); params.put("pageSize",20); String result=requestContent(requestUrl,params,method); System.out.println(result); } }
平台的文档参数都写的比较清晰,具体可以网盘数据查看,返回结果有json/xml两种形式:
{ "data": { "result": [{ "id": 15229, "title": "19.STM32+UCOSIII开发", "url": "https://pan.baidu.com/s/1jHVppmm", "size": "0 B", "shareTime": 1544196520000, "shareUser": "men****gwc", "isDir": "1", "originId": 1, "originName": "百度网盘", "categoryId": 6, "categoryName": "文件夹(压缩)", "password": "1h7h", "acqTime": 1544196520000, "content": "文件|4,程序源码|3,ALIENTEK战舰STM32F1 V3开发板原理图|2,ALIENTEK战舰STM32F1 V3开发板视频教程|1,ALIENTEK战舰STM32F1 V3开发板入门资料|联系我们.pdf|STM32F1开发指南-库函数版本_V3.1 .pdf|STM32F1开发指南-寄存器版本_V3.1 .pdf|STM32F1 UCOS开发手册_V2.0.pdf|STM32F1 LWIP开发手册(DM9000版)_V1.1.pdf|STM32F1 EMWIN开发手册_V2.0.pdf|01", "uk": "2568959939", "shareId": "3221440608", "fileCount": 12, "fromTable": 5, "uniqueKey": "15a3c21502524cde3dca0602265d0de2", "shortUrl": "1jHVppmm", "extendFiles": [{ "fsId": "679418566138045", "serverFilename": "文件", "size": "0 B" }, { "fsId": "276424880413983", "serverFilename": "4,程序源码", "size": "0 B" }, { "fsId": "512606928244026", "serverFilename": "3,ALIENTEK战舰STM32F1 V3开发板原理图", "size": "2.9 GB" }, { "fsId": "490793316644212", "serverFilename": "2,ALIENTEK战舰STM32F1 V3开发板视频教程", "size": "3.2 GB" }, { "fsId": "449624001387403", "serverFilename": "1,ALIENTEK战舰STM32F1 V3开发板入门资料", "size": "3.7 GB" }, { "fsId": "934962552301526", "serverFilename": "联系我们.pdf", "size": "283 MB" }, { "fsId": "151892956852061", "serverFilename": "STM32F1开发指南-库函数版本_V3.1 .pdf", "size": "8.1 MB" }, { "fsId": "277550860315906", "serverFilename": "STM32F1开发指南-寄存器版本_V3.1 .pdf", "size": "2.0 GB" }, { "fsId": "675377464375217", "serverFilename": "STM32F1 UCOS开发手册_V2.0.pdf", "size": "3.3 GB" }, { "fsId": "686926257121399", "serverFilename": "STM32F1 LWIP开发手册(DM9000版)_V1.1.pdf", "size": "3.7 GB" }, { "fsId": "829790437997820", "serverFilename": "STM32F1 EMWIN开发手册_V2.0.pdf", "size": "12.2 MB" }, { "fsId": "383158876469280", "serverFilename": "01", "size": "0 B" }] }], "amount": 1, "totalPage": 1, "time": 0.20107889, "currentPage": 1 }, "errorMessage": "成功", "errorCode": 0, "error": "success" }
到此,相信大家对“如何用python获取网盘数据”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!