徐德亮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
[url]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[/url]另存为保存
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值