The example of this article tells the way Java acquires the real download link of Baidu's network disk. Share it for everyone for your reference. The specifics are as follows:
There is still a problem. The same IP will have a verification code after obtaining the same IP and fails to obtain failure. Interested friends can improve this.
The back <Map <string, Object >> in the return includes: Filename (file name), URL (real chain address)
Httprequest.java is as follows:
Import java.io.BufferedReader; Import Java.io.ioException; Import Java.Io.InputStream; Import java.inputStreamReader; Import File; Import Java.lang.reflet.Method; Import Java.net.httpurlConnection ; Import Java.net.url; Public Class httprequest {Public Story String GetData (String U) Throws Exception {String Re = "" ""; URL URL = New (U) ; HttpurlConnection httpurlconnection = (httpurlConnection) url .opeenconnection (); httpurlConnection.setRequestMethod ("get"); httpurlconnection.setdoinput (true); httpurlConnection.SetDOUTPUT (true); inputStream is = http UrlConnection.getInputStream (); inputStreamReader isr = new inputStreamReamReader (is); bufferedReader bufferedReader = new bufferedReader (ISR) String il = "";; ((il = bufferedReader.readline ())! = NULL) {re + = il + "/n";} Return Re;}}
Getting method:
Import java.net.urlencoder; Import Java.util.arrayList; Import Java.util.hashmap; Import java.util.list; Import java.util.map; Import .Jsonarray; Import org.json.jsonObject; Import ORG.JSOUP.JSOUP; Import org.jsoup.nodes.document; Public Class Baidunetdisk {Public Static List <Map <string, Object >> TH ROWS Exception {list <string> fs_id = New ArrayList <string> ( ); <Map <string, Object >> List = New ArrayList <Map <string, Object >> (); Document Doc = JSOUP.CONNECT (url) .get (); ); int a = html.indexof ("{ /" typicalPath "); int b = html.indexof (" yundata.getCon "); int SIGN_HEAD = html.indexof (" yundata.sign = /""); int _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 shame_id_foot = html.indexof ("yundata.sign"); string sign = html.substring (sign_head, sign_foot); sign = sign.substrin. g (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.indexo f ("/"; "); System.out .println (share_id); html = html.substring (a, b); a = html.indexof ("{/" typicalPath "); b = html.indexof ("}; "); ray ("" [" + html.substring (a, b + 1) +"] "); jsonObject jsonObject = jsonarray.getjsonObject (0); string uk = jsonObject.getstring (" uk "); = jsonObject.getString ("Shareid "); String path = urlencoder.encode (jsonObject.getString (" TypicalPath ")," UTF-8 "); ") +"] "); jsonObject = jsonarray.getjsonObject (0); jsonarray = new jsonarray (jsonObject.getString ("List"); jsonObject = jsonarray.getjsonObject (0); String sonObject.getString ("APP_ID"); if (JSONObject.getStringstring ( "ISDIR"). Equals ("1")) {string url1 = "http://pan.baidu.com/share/list?uk=" + uk + "& shareid =" + shareid + "& num = 100 & dir = " + PATH +" & Order = Time & DESC = 1 & _ = " + Time +" & BDSTOKEN = C51077ce0E0E0E0E316066612A13FBCD4 & Clienttype = 0 & Web = 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 ;} Final int size = jsonarray.length () ; for (int i = 0; I <size; i ++) {map <string, object> map = new hashmap <string, object> (); jsonObject = jsonarray.getjsonobject (i); ame = jsonObject.getString (" Server_filename "); Map.put (" Filename ", FILENAME); fs_id.add (jsonObject.getString (" FS_ID "); string fileinfo = httprequest .Getdata (" http:// Pan. baidu.com/api/shaRdownload ? SIGN = " + SIGN +" × TAMP = " + Time +" & BDSTOKEN = C51077ce0e3131606612A13FBCD4 & 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 +"]; getstring ("Errno") .equals ("0")) {jsonarray2 = new jsonarray (json_data.getstring ("list"); json_data = jsonarray2.getjsonObject (0); Map.put ("url", json_data.getstr ing ("dlink")) ;} Else if (json_data.getstring ("Errno"). Equals ("-20") {Return Null; // String Getvercode ();} Else {RETURN NULL;} List.add (map);} urn List ;}}
It is hoped that this article is helpful to everyone's Java program design.