新聞中心
本篇內(nèi)容主要講解“如何用python獲取網(wǎng)盤數(shù)據(jù)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“如何用python獲取網(wǎng)盤數(shù)據(jù)”吧!
沾化網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)于2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。
隨著版權(quán)越來越重,做個電影站、磁力站、小說站已經(jīng)越來越難,而網(wǎng)盤搜索的話由于背靠百度大哥,還相對好一些,但是百度壓力也是越來越大,這個領(lǐng)域獲取數(shù)據(jù)其實(shí)也基本不太可能。好在有些團(tuán)隊(duì)?wèi){借著長期的數(shù)據(jù)儲備,積累了很多相關(guān)數(shù)據(jù),可以采用直接調(diào)用數(shù)據(jù)的形式實(shí)現(xiàn),目前做的比較好的當(dāng)屬小蔥計(jì)算,這是小編最近才發(fā)現(xiàn)的一個平臺,也大概看了下demo,確實(shí)很容易,以python為例:
# -*- coding: utf-8 -*- # flake8: noqa __author__ = 'wukong' import urllib from urllib import urlencode #配置您申請的appKey和openId app_key="***" open_id="***" """ request_url 請求地址 params 請求參數(shù) 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型轉(zhuǎn)為請求參數(shù)型 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 請求參數(shù) * @param method 請求方法 * @return 請求結(jié)果 * @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); } //默認(rèn)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); } //參數(shù)配置 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(); } } //讀取數(shù)據(jù) 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); } }
平臺的文檔參數(shù)都寫的比較清晰,具體可以網(wǎng)盤數(shù)據(jù)查看,返回結(jié)果有json/xml兩種形式:
{ "data": { "result": [{ "id": 15229, "title": "19.STM32+UCOSIII開發(fā)", "url": "https://pan.baidu.com/s/1jHVppmm", "size": "0 B", "shareTime": 1544196520000, "shareUser": "men****gwc", "isDir": "1", "originId": 1, "originName": "百度網(wǎng)盤", "categoryId": 6, "categoryName": "文件夾(壓縮)", "password": "1h7h", "acqTime": 1544196520000, "content": "文件|4,程序源碼|3,ALIENTEK戰(zhàn)艦STM32F1 V3開發(fā)板原理圖|2,ALIENTEK戰(zhàn)艦STM32F1 V3開發(fā)板視頻教程|1,ALIENTEK戰(zhàn)艦STM32F1 V3開發(fā)板入門資料|聯(lián)系我們.pdf|STM32F1開發(fā)指南-庫函數(shù)版本_V3.1 .pdf|STM32F1開發(fā)指南-寄存器版本_V3.1 .pdf|STM32F1 UCOS開發(fā)手冊_V2.0.pdf|STM32F1 LWIP開發(fā)手冊(DM9000版)_V1.1.pdf|STM32F1 EMWIN開發(fā)手冊_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戰(zhàn)艦STM32F1 V3開發(fā)板原理圖", "size": "2.9 GB" }, { "fsId": "490793316644212", "serverFilename": "2,ALIENTEK戰(zhàn)艦STM32F1 V3開發(fā)板視頻教程", "size": "3.2 GB" }, { "fsId": "449624001387403", "serverFilename": "1,ALIENTEK戰(zhàn)艦STM32F1 V3開發(fā)板入門資料", "size": "3.7 GB" }, { "fsId": "934962552301526", "serverFilename": "聯(lián)系我們.pdf", "size": "283 MB" }, { "fsId": "151892956852061", "serverFilename": "STM32F1開發(fā)指南-庫函數(shù)版本_V3.1 .pdf", "size": "8.1 MB" }, { "fsId": "277550860315906", "serverFilename": "STM32F1開發(fā)指南-寄存器版本_V3.1 .pdf", "size": "2.0 GB" }, { "fsId": "675377464375217", "serverFilename": "STM32F1 UCOS開發(fā)手冊_V2.0.pdf", "size": "3.3 GB" }, { "fsId": "686926257121399", "serverFilename": "STM32F1 LWIP開發(fā)手冊(DM9000版)_V1.1.pdf", "size": "3.7 GB" }, { "fsId": "829790437997820", "serverFilename": "STM32F1 EMWIN開發(fā)手冊_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獲取網(wǎng)盤數(shù)據(jù)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
分享名稱:如何用python獲取網(wǎng)盤數(shù)據(jù)
當(dāng)前地址:http://www.ef60e0e.cn/article/jjcohp.html