您好,登錄后才能下訂單哦!
本篇內容主要講解“如何用python獲取網盤數據”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何用python獲取網盤數據”吧!
隨著版權越來越重,做個電影站、磁力站、小說站已經越來越難,而網盤搜索的話由于背靠百度大哥,還相對好一些,但是百度壓力也是越來越大,這個領域獲取數據其實也基本不太可能。好在有些團隊憑借著長期的數據儲備,積累了很多相關數據,可以采用直接調用數據的形式實現,目前做的比較好的當屬小蔥計算,這是小編最近才發現的一個平臺,也大概看了下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(Map<String,Object> params) { if(params==null){return "";}; StringBuilder sb = new StringBuilder(); for (Map.Entry<String,Object> 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<String,Object> 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<String,Object> params=new HashMap<String,Object>(); 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.<span style='color:red'>STM</span><span style='color:red'>32</span>+<span style='color:red'>UCOSIII</span><span style='color:red'>開發</span>", "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戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板原理圖|2,ALIENTEK戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板視頻教程|<span style='color:red'>1</span>,ALIENTEK戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板入門資料|聯系我們.pdf|<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span><span style='color:red'>開發</span>指南-庫函數版本_V3.<span style='color:red'>1</span> .pdf|<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span><span style='color:red'>開發</span>指南-寄存器版本_V3.<span style='color:red'>1</span> .pdf|<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> UCOS<span style='color:red'>開發</span>手冊_V2.0.pdf|<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> LWIP<span style='color:red'>開發</span>手冊(DM9000版)_V<span style='color:red'>1</span>.<span style='color:red'>1</span>.pdf|<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> EMWIN<span style='color:red'>開發</span>手冊_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戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板原理圖", "size": "2.9 GB" }, { "fsId": "490793316644212", "serverFilename": "2,ALIENTEK戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板視頻教程", "size": "3.2 GB" }, { "fsId": "449624001387403", "serverFilename": "<span style='color:red'>1</span>,ALIENTEK戰艦<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> V3<span style='color:red'>開發</span>板入門資料", "size": "3.7 GB" }, { "fsId": "934962552301526", "serverFilename": "聯系我們.pdf", "size": "283 MB" }, { "fsId": "151892956852061", "serverFilename": "<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span><span style='color:red'>開發</span>指南-庫函數版本_V3.<span style='color:red'>1</span> .pdf", "size": "8.1 MB" }, { "fsId": "277550860315906", "serverFilename": "<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span><span style='color:red'>開發</span>指南-寄存器版本_V3.<span style='color:red'>1</span> .pdf", "size": "2.0 GB" }, { "fsId": "675377464375217", "serverFilename": "<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> UCOS<span style='color:red'>開發</span>手冊_V2.0.pdf", "size": "3.3 GB" }, { "fsId": "686926257121399", "serverFilename": "<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> LWIP<span style='color:red'>開發</span>手冊(DM9000版)_V<span style='color:red'>1</span>.<span style='color:red'>1</span>.pdf", "size": "3.7 GB" }, { "fsId": "829790437997820", "serverFilename": "<span style='color:red'>STM</span><span style='color:red'>32</span>F<span style='color:red'>1</span> EMWIN<span style='color:red'>開發</span>手冊_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獲取網盤數據”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。