Anyone who wants php can download the test http://www.jb51.net/codes/83179.html here
Copy codeThe Code is as follows: import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. MalformedURLException;
Import java.net. URL;
Import net. sf. json .*;
Public class test2 {
/**
* @ Param args
* @ Throws IOException
*/
Public static void main (String [] args) throws IOException {
// TODO Auto-generated method stub
String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html ";
// Obtain the string after the id, that is, "XMjU0MjI2NzY0.html"
Int no = url. indexOf ("id _");
// Obtain the id value, that is, "XMjU0MjI2NzY0"
String videoId = url. substring (no + 3, url. indexOf (". html "));
// URL object for obtaining video information data
URL myurl = new URL ("http://v.youku.com/player/getPlayList/VideoIDS/" + videoId + "/timezone/+ 08/version/5/source/out? Password = & ran = 2513 & n = 3 ");
// Obtain the input stream from the URL object
InputStreamReader isr = new InputStreamReader (myurl. openStream ());
// Encapsulation
BufferedReader br = new BufferedReader (isr );
// Read the text in readLine.
String urls = br. readLine ();
// Close the stream
Br. close ();
// Obtain the json object
JSONObject json = JSONObject. fromObject (urls );
// Obtain json data (within data)
JSONArray arr = json. getJSONArray ("data ");
// Obtain and print the logo Value
System. out. println (JSONObject. fromObject (arr. get (0). get ("logo "));
}
}
Another method that does not use json is the first one.Copy codeThe Code is as follows: import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. URL;
Public class test1 {
/**
* @ Param args
* @ Throws IOException
*/
Public static void main (String [] args) throws IOException {
// TODO Auto-generated method stub
// Set the video address
String url = "http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html ";
// Obtain the string after the id, that is, "XMjU0MjI2NzY0.html"
Int no = url. indexOf ("id _");
// Obtain the id value, that is, "XMjU0MjI2NzY0"
String videoId = url. substring (no + 3, url. indexOf (". html "));
// URL object for obtaining video information data
URL myurl = new URL ("http://v.youku.com/player/getPlayList/VideoIDS/" + videoId + "/timezone/+ 08/version/5/source/out? Password = & ran = 2513 & n = 3 ");
// Obtain the input stream from the URL object
InputStreamReader isr = new InputStreamReader (myurl. openStream ());
// Encapsulation
BufferedReader br = new BufferedReader (isr );
// ReadLine: Get the text and then cut the information in the text "\/"
String [] urls = br. readLine (). split ("\\/");
Isr. close ();
Br. close ();
// Because the information data is in a fixed format, the fourth element must be what we need.
String target = urls [3];
// Continue to cut the above results
String imgid = target. substring (0, target. indexOf ("\""));
// Put together the addresses we need.
String img = "http://g2.ykimg.com/" + imgid;
System. out. println (img );
/*
Result: http://g2.ykimg.com/1100641F464D8FBF5FA3D90209C8DF96B67E2C-567E-AB53-C132-D7787FC966AB
*/
}
}