其他地址自己寻找并替换类似上面的音频地址
可以使用 Export -> Runable JAR file
勾选 Extract required libaries into generated JAR
然后cmd运行 java -jar xx.jar 就可以运行下载了
package com; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class XiaoShuo { //主入口 public static void main(String[] args) { //修改目录地址可以下载任意小说 // String url = "http://www.ting56.com/mp3/8205.html"; // args=new String[]{url}; if(args!=null && args.length>0 && args[0].startsWith("http://www.ting56.com/mp3/")){ game(args[0]); }else{ System.out.println("传入参数有误,举例 java -jar ting56.jar http://www.ting56.com/mp3/8205.html"); } } //正则 public static Matcher getRegex(String text, String regex) { Matcher mc = Pattern.compile(regex).matcher(text); return mc; } //程序入口 public static void game(String url){ try { Document d = Jsoup.connect(url).get(); String title = d.getElementsByClass("tit").get(0).getElementsByTag("h1").text(); title = (title!=null&&!title.equals(""))?title:System.currentTimeMillis()+""; Element el = d.getElementById("vlink_1"); Elements es = el.getElementsByTag("li"); for(Element e:es){ //标题 System.out.println(e.text()); Document d1 = Jsoup.connect("http://www.ting56.com"+e.getElementsByTag("a").attr("href")).get(); Matcher mc = getRegex(d1.html(), "FonHen_JieMa\\('([0-9,*]*)'\\)"); if(mc.find()){ String mi = mc.group(1); String tArr[] = mi.split("\\*"); int n = tArr.length; StringBuffer sb = new StringBuffer(); for(int i=0;i<n;i++){ if(!tArr[i].equals("")) sb.append(""+String.valueOf((char)Integer.parseInt(tArr[i]))); } String down = sb.toString().split("\\&")[0]; String down2 = sb.toString().split("\\&")[2]; //下载地址 System.out.println(down); // System.out.println(down2); saveToFile(down, "/down/"+title+"/"+e.text()+"."+down2); // System.out.println(e.text()+"."+down2); } // System.out.println(d2); } } catch (Exception e) { e.printStackTrace(); } } /** * 保存文件 * @param destUrl 文件来源 * @param savepath 保存路径 含文件名 */ public static void saveToFile(String destUrl,String savepath) { FileOutputStream fos = null; BufferedInputStream bis = null; HttpURLConnection httpUrl = null; URL url = null; int BUFFER_SIZE = 1024; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; try { File dirFile = null; dirFile = new File(savepath.substring(0,savepath.lastIndexOf("/"))); if (!(dirFile.isDirectory()))dirFile.mkdirs(); url = new URL(destUrl); httpUrl = (HttpURLConnection)url.openConnection(); httpUrl.connect(); bis = new BufferedInputStream(httpUrl.getInputStream()); fos = new FileOutputStream(savepath); while ((size = bis.read(buf)) != -1) { fos.write(buf, 0, size); } fos.flush(); }catch (Exception e){ e.printStackTrace(); }finally { try { fos.close(); bis.close(); httpUrl.disconnect(); }catch (Exception e) { e.printStackTrace(); } } } }
附件的jsoup是java调用使用的jar包
------------ 2017-05-09 ----------- 补充内容 上面代码改了下传参
没有java环境的自己搜jre1.7下载安装
有java环境的直接下载 ting56.jar
放到D盘目录通过cmd调java运行
d:\>java -jar ting56.jar http://www.ting56.com/mp3/4303.html
参数连接要使用列表页,可以访问 http://www.ting56.com/mp3/4303.html
下载文件在你运行这个jar的磁盘下down目录里
比如你在D盘下运行的就会生成 d:\down\超禁忌游戏有声小说\xx.mp3