Java get Baidu Network disk Real Download link method _java

Source: Internet
Author: User
Tags int size

This article is an example of Java to obtain the real download Baidu Network link method. Share to everyone for your reference. Specifically as follows:

At present, there is a problem, the same IP in the acquisition of 3 times after the verification code will be lost, interested friends can be perfected.

List<map<string returned, the Map in object>> contains: filename (filename), url (real chain address)

Httprequest.java is as follows:

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;
 }
}

Get method:

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 {L
  ist<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&amp ; _= "+ Time +" &bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0&web=1&amp
   ; 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 +) &ti Mestamp= "+ Time +" &bdstoken=c51077ce0e0e313a16066612a13fbcd4&channel=chunlei&clienttype=0& web=1&app_id=250528&encrypt=0&product=share&uk= "+ UK +" &primaryid= "+ share_id +" &fid_li
   st=%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;

 }
}

I hope this article will help you with your Java programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.