`
happysoul
  • 浏览: 403506 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

徐德亮119集济公传下载

 
阅读更多


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PingShu {

	public static String gethtml(String cookie,String htmltype,String httpurl,Boolean changeline) throws IOException {
		URL urlx = new URL(httpurl);
		HttpURLConnection uc = (HttpURLConnection) urlx.openConnection();
		uc.setDoInput(true);
		uc.setUseCaches(false);
		uc.setRequestMethod("GET");
		uc.setInstanceFollowRedirects(true);
		uc.setConnectTimeout(10*1000);			//10秒连接超时
		uc.setReadTimeout(30*1000);				//30秒读取超时
//		uc.setRequestProperty("Cache-Control", "no-cache, must-revalidate");
//		uc.setRequestProperty("Connection", "Keep-Alive");
//		uc.setRequestProperty("Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-shockwave-flash, */*");
		uc.setRequestProperty("Accept-Language", "zh-cn");
//		uc.setRequestProperty("Accept-Encoding", "gzip, deflate");
//		uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		uc.setRequestProperty("User-Agent","Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; SV1)");
		if(cookie!=null && !cookie.trim().equals(""))uc.setRequestProperty("Cookie",cookie);
		InputStream inputstream = uc.getInputStream();
		BufferedReader bufferedreader = null;
		String contentType = uc.getContentType();
		if(contentType!=null && !contentType.equals("") && contentType.indexOf("charset=")!=-1){
			if(htmltype==null || htmltype.equals(""))
				htmltype = contentType.substring(contentType.indexOf("charset=") + 8).trim();
		}
		
		if(htmltype==null||htmltype.trim().equals(""))bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
		else bufferedreader = new BufferedReader(new InputStreamReader(inputstream,htmltype));
		String s1;
		String vhtml = "";
		while ((s1 = bufferedreader.readLine()) != null) {
			if(changeline!=null && changeline==false)vhtml = vhtml + s1;
			else vhtml = vhtml + "\n" + s1;
		}
		return vhtml;
	}
	
	public static Matcher getRegex(String text, String regex) {
		Matcher mc = Pattern.compile(regex).matcher(text);
		return mc;
	}
	
	public static void main(String[] args) throws IOException {
		
		String html = gethtml(null, null, "http://www.tingcd.com/thread-4803-1-1.html", true);
		
		Matcher mc = getRegex(html, "<a href=\"([\\d]+.html)\"");
		int i = 1;
		while(mc.find()){
                           if(i==91)i++;
			String count = "";
			if(i<10)count="00"+i;
			else if(i<100)count="0"+i;
			else count = i+"";
			String html1 = gethtml(null, null, "http://www.tingcd.com/"+mc.group(1), true);
			Matcher mc1 = getRegex(html1, "(attachment.php\\?aid=[^']+)");
			if(mc1.find()){
				System.out.print(count+"	");
				System.out.println(mc1.group(1));
//下载文件保存在 /nas/xudeliang/ 目录下				
saveToFile("http://www.tingcd.com/"+mc1.group(1),"/nas/xudeliang/"+count+".mp3");
				i++;
			}
		}
	}
	

	/**
	 * 保存文件
	 * @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();
			}
		}  
	}  
	
}



缺少91
http://163f-d.ysx8.net:8000/%E7%9B%B8%E5%A3%B0%E5%B0%8F%E5%93%81/%E5%BE%90%E5%BE%B7%E4%BA%AE/%E5%BE%90%E5%BE%B7%E4%BA%AE_%E6%B5%8E%E5%85%AC%E4%BC%A0/[%E6%88%91%E5%90%AC%E8%AF%84%E4%B9%A6%E7%BD%91www.5tps.com]%E5%BE%90%E5%BE%B7%E4%BA%AE%E6%B5%8E%E5%85%AC%E4%BC%A0091.mp3?11210548339664x1447059516x11210836952418-6191918138682676967?3另存为保存
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics