Get Youku video from Java

Source: Internet
Author: User

Through Java to get Youku video, now many social sites have this feature, the user input Youku video address, can find the corresponding video and video thumbnails, some community sites can also get the length of the video.

For example: Sina Weibo has this function, when the user input video URL, you can get the corresponding video address and video thumbnail.

Java.io.unsupportedencodingexception;03import Import Java.io.ioexception;02import java.net.malformedurlexception;04 05import Org.jsoup.jsoup;06import Org.jsoup.nodes.document;07import org.jsoup.nodes.element;08 09 10/**11* get Youku video 12* @author sunlightcs13* 2011-3-2914* http://hi.juziku.com/sunlightcs/ 15*/16public class Videotest {+ public static void main (string[] args) throws exception{19 String pic = Gete        Lementattrbyid ("S_sina", "href"); int local = Pic.indexof ("pic="); pic = pic.substring (local+4); 22 System.out.println ("video thumbnail:" +pic); String Flashurl = Getelementattrbyid ("Link2", "value"); System.out.println ("Video address:" +flashurl); String time = Getelementattrbyid ("Download" , "href"); String []arrays = Time.split ("\\|"); Time = arrays[4];32 System.out.println ("Video duration:" +time); 33 34}35 36 37/**38 * Based on The ID key of the HTML and belongs to the name, gets the value 39 *ID key for @param ID HTML * @param attrname belongs to the name of the * @return return attribute value */43 private static String getelementattr Byid (string ID, String attrname) throws exception{44 Document doc = geturlcontent (), Element et = Doc.getel     Ementbyid (ID); String attrValue = Et.attr (attrname); attrvalue;49}50 51 52 53/**54 * Get the content of the Youku page */56 private static Document geturlcontent () throws Malformedurlexception, Ioexcepti On, unsupportedencodingexception {Document doc = jsoup.connect ("http://v.youku.com/v_show/id_XMjU0MjI2NzY0.html" ). Data ("Query", "Java") useragent ("Mozilla"), Cookie ("auth", "token"). Timeo UT (+). Post (); Doc;64}65 66}


Jar Package Used
Jsoup-1.5.2.jar

Related Article

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.