亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

java獲取百度網(wǎng)盤真實(shí)下載鏈接的方法

 更新時(shí)間:2015年07月16日 16:30:39   作者:王滔  
這篇文章主要介紹了java獲取百度網(wǎng)盤真實(shí)下載鏈接的方法,涉及java針對(duì)URL操作及頁(yè)面分析的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了java獲取百度網(wǎng)盤真實(shí)下載鏈接的方法。分享給大家供大家參考。具體如下:

目前還存在一個(gè)問(wèn)題,同一ip在獲取3次以后會(huì)出現(xiàn)驗(yàn)證碼,會(huì)獲取失敗,感興趣的朋友對(duì)此可以加以完善。

返回的List<Map<String, Object>>  中的map包含:fileName( 文件名),url(實(shí)鏈地址)

HttpRequest.java如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpRequest {
 public static String getData(String u) throws Exception {
  String re="";
    URL url = new URL(u);
  HttpURLConnection httpURLConnection = (HttpURLConnection) url
    .openConnection();
  httpURLConnection.setRequestMethod("GET");
  httpURLConnection.setDoInput(true);
  httpURLConnection.setDoOutput(true);
  InputStream is = httpURLConnection.getInputStream();
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader bufferedReader = new BufferedReader(isr);
  String iL = "";
  while ((iL = bufferedReader.readLine()) != null) {
   re += iL + "\n";
  }
  return re;
 }
}

獲取方法:

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class BaiduNetDisk {
 public static List<Map<String, Object>> getUrl(String url) throws Exception {
  List<String> fs_id = new ArrayList<String>();
  List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
  Document doc = Jsoup.connect(url).get();
  String html = doc.toString();
  int a = html.indexOf("{\"typicalPath");
  int b = html.indexOf("yunData.getCon");
  int sign_head = html.indexOf("yunData.SIGN = \"");
  int sign_foot = html.indexOf("yunData.TIMESTAMP");
  int time_head = html.indexOf("yunData.TIMESTAMP = \"");
  int time_foot = html.indexOf("yunData.SHARE_UK");
  int share_id_head = html.indexOf("yunData.SHARE_ID = \"");
  int share_id_foot = html.indexOf("yunData.SIGN ");
  String sign = html.substring(sign_head, sign_foot);
  sign = sign.substring(sign.indexOf("\"") + 1, sign.indexOf("\";"));
  String time = html.substring(time_head, time_foot);
  time = time.substring(time.indexOf("\"") + 1, time.indexOf("\";"));
  String share_id = html.substring(share_id_head, share_id_foot);
  share_id = share_id.substring(share_id.indexOf("\"") + 1,
    share_id.indexOf("\";"));
  System.out.println(share_id);
  html = html.substring(a, b);
  a = html.indexOf("{\"typicalPath");
  b = html.indexOf("};");
  JSONArray jsonArray = new JSONArray("[" + html.substring(a, b + 1)
    + "]");
  JSONObject jsonObject = jsonArray.getJSONObject(0);
  String uk = jsonObject.getString("uk");
  String shareid = jsonObject.getString("shareid");
  String path = URLEncoder.encode(jsonObject.getString("typicalPath"),
    "utf-8");
  jsonArray = new JSONArray("[" + jsonObject.getString("file_list") + "]");
  jsonObject = jsonArray.getJSONObject(0);
  jsonArray = new JSONArray(jsonObject.getString("list"));
  jsonObject = jsonArray.getJSONObject(0);
  String app_id = jsonObject.getString("app_id");
  if (jsonObject.getString("isdir").equals("1")) {
   String url1 = "http://pan.baidu.com/share/list?uk="
     + uk
     + "&shareid="
     + shareid
     + "&page=1&num=100&dir="
     + path
     + "&order=time&desc=1&_="
     + time
     + "&bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0&web=1&app_id="
     + app_id;
   String fileListJson = HttpRequest.getData(url1);
   System.out.println(fileListJson);
   jsonArray = new JSONArray("[" + fileListJson + "]");
   jsonObject = jsonArray.getJSONObject(0);
   jsonArray = new JSONArray(jsonObject.getString("list"));
  }
  final int size = jsonArray.length();
  for (int i = 0; i < size; i++) {
   Map<String, Object> map = new HashMap<String, Object>();
   jsonObject = jsonArray.getJSONObject(i);
   String fileName = jsonObject.getString("server_filename");
   map.put("fileName", fileName);
   fs_id.add(jsonObject.getString("fs_id"));
   String fileInfo = HttpRequest
     .getData("http://pan.baidu.com/api/sharedownload?sign="
       + sign
       + "&timestamp="
       + time
       + "&bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0&web=1&app_id=250528&encrypt=0&product=share&uk="
       + uk + "&primaryid=" + share_id + "&fid_list=%5B"
       + fs_id.get(i) + "%5D");
   JSONArray jsonArray2 = new JSONArray("[" + fileInfo + "]");
   JSONObject json_data = jsonArray2.getJSONObject(0);
   if (json_data.getString("errno").equals("0")) {
    jsonArray2 = new JSONArray(json_data.getString("list"));
    json_data = jsonArray2.getJSONObject(0);
    map.put("url", json_data.getString("dlink"));
   } else if (json_data.getString("errno").equals("-20")) {
    return null;
    // String getVerCode();
   } else {
    return null;
   }
   list.add(map);
  }
  return list;
 }
}

希望本文所述對(duì)大家的java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • EasyExcel工具讀取Excel空數(shù)據(jù)行問(wèn)題的解決辦法

    EasyExcel工具讀取Excel空數(shù)據(jù)行問(wèn)題的解決辦法

    EasyExcel是阿里巴巴開(kāi)源的一個(gè)excel處理框架,以使用簡(jiǎn)單,節(jié)省內(nèi)存著稱,下面這篇文章主要給大家介紹了關(guān)于EasyExcel工具讀取Excel空數(shù)據(jù)行問(wèn)題的解決辦法,需要的朋友可以參考下
    2022-08-08
  • Springcloud RestTemplate服務(wù)調(diào)用代碼實(shí)例

    Springcloud RestTemplate服務(wù)調(diào)用代碼實(shí)例

    這篇文章主要介紹了Springcloud RestTemplate服務(wù)調(diào)用代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 如何讀取properties或yml文件數(shù)據(jù)并匹配

    如何讀取properties或yml文件數(shù)據(jù)并匹配

    這篇文章主要介紹了如何讀取properties或yml文件數(shù)據(jù)并匹配方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • Java?File類的概述及常用方法使用詳解

    Java?File類的概述及常用方法使用詳解

    Java?File類的功能非常強(qiáng)大,下面這篇文章主要給大家介紹了關(guān)于Java中File類的概述及常用方法使用,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • java return用法實(shí)例詳解

    java return用法實(shí)例詳解

    在本篇文章里小編給大家整理的是關(guān)于java return用法以及相關(guān)知識(shí)點(diǎn)總結(jié),需要的朋友們參考下。
    2019-08-08
  • 淺談Java隨機(jī)數(shù)的原理、偽隨機(jī)和優(yōu)化

    淺談Java隨機(jī)數(shù)的原理、偽隨機(jī)和優(yōu)化

    這篇文章主要介紹了淺談Java隨機(jī)數(shù)的原理、偽隨機(jī)和優(yōu)化,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-01-01
  • Java基于Javafaker生成測(cè)試數(shù)據(jù)

    Java基于Javafaker生成測(cè)試數(shù)據(jù)

    這篇文章主要介紹了Java基于Javafaker生成測(cè)試數(shù)據(jù)的方法,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-12-12
  • java生成文件夾和文件的簡(jiǎn)單示例分享

    java生成文件夾和文件的簡(jiǎn)單示例分享

    這篇文章主要介紹了java生成文件夾和文件的簡(jiǎn)單示例,需要的朋友可以參考下
    2014-04-04
  • java類加載相關(guān)知識(shí)總結(jié)

    java類加載相關(guān)知識(shí)總結(jié)

    今天帶大家復(fù)習(xí)Java基礎(chǔ)知識(shí),文章對(duì)Java類加載做了詳細(xì)介紹,對(duì)正在學(xué)習(xí)java的小伙伴很有幫助,需要的朋友可以參考下
    2021-05-05
  • IDEA自動(dòng)生成TestNG的testng.xml的插件方法

    IDEA自動(dòng)生成TestNG的testng.xml的插件方法

    這篇文章主要介紹了IDEA自動(dòng)生成TestNG的testng.xml的插件方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04

最新評(píng)論