Import Java.io.ioexception;import org.jsoup.jsoup;import org.jsoup.nodes.document;import org.jsoup.nodes.Element; Import Org.jsoup.select.elements;public class Snippet {public static void main (string[] args) throws ioexception{string B Aseurl = "http://www.wwenglish.com"; Document Listdoc = Jsoup.connect ("http://www.wwenglish.com/en/club/cnntv/"). get (); Elements dd = listdoc.select ("td.category td.category_main a.list"); for (Element element:dd) {String Mp3pageurl = baseUrl + element.attr ("href"); System.out.println (Mp3pageurl); Document Mp3doc = Jsoup.connect (Mp3pageurl). get (); Elements mp3elements = Mp3doc.select ("A.wwmp3"); if (null! = mp3elements && mp3elements.size () >0) {String Mp3url = baseUrl + mp3elements.get (0). at TR ("href"); String fileName = mp3url.substring (Mp3url.lastindexof ("/")); System.out.println (FileName); DownLoad thread = new DownLoad (Mp3url, "F:/wwenglish" +filename); Thread.Start (); } }}}
Import Java.io.bufferedoutputstream;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.inputstream;import Java.io.outputstream;import Java.net.url;public class DownLoad extends Thread {public DownLoad (String mp3url, string filepath) {//Open a URL streamtry {URL url = new URL (mp3url); InputStream in = Url.openstre AM (); OutputStream out = new Bufferedoutputstream (new FileOutputStream (filepath)), for (int b; (b = In.read ())! =-1;) {Out.write (b);} Out.close (); In.close ();} catch (IOException e) {e.printstacktrace ();}}}
Implemented the following link described in the function, the original code is not complete. There is no use of HttpClient, and the use of Jsoup alone achieves the goal.
Simple to use httpclient jsoup to do the extraction of Wang Wang English
The library relies on the following:
<?xml version= "1.0" encoding= "UTF-8"? ><classpath><classpathentry kind= "src" path= "src"/>< Classpathentry kind= "Con" path= "org.eclipse.jdt.launching.jre_container/ org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/javase-1.8 "/><classpathentry kind=" Lib "path=" H :/mavenrepository/org/jsoup/1.8.1/jsoup-1.8.1.jar "/><classpathentry kind=" Lib "path=" H:/MavenRepository/ Org/apache/httpcomponents/httpclient/4.0/httpclient-4.0.jar "/><classpathentry kind=" Lib "path=" H:/ Mavenrepository/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar "/><classpathentry kind=" Output "path=" Bin "/></classpath>
Use Jsoup and multithreading to download Wang Wang English MP3