场景1:
项目放到国外服务器,配置ftp,上传老掉线,网速实在不如人意
解决:
wget方式下载,-c就ok,把你的东西放到一个url可以直接下载的地方,俺测试下了360云盘,报错不支持,可以找速度快并且稳定的地方上次,不行那就自己动手,放nginx里面,远程下载,不用操心
nuhop xxx & ,到时候看nohup.out就ok
场景2
收集网页分析数据,wget方式可以下载全站的,如果觉得速度太慢,不给力,自己动手
附带简单的下载代码
public class SimpleDownLoadHtmlUtil {
public Logger log = Logger.getLogger(getClass());
public static class DownLoadParams {
// 下载链接
private String uri;
// 开始Id
private int startId;
// 结束id
private int endId;
// 下载存放目录
private String downLoadDir;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public int getStartId() {
return startId;
}
public void setStartId(int startId) {
this.startId = startId;
}
public int getEndId() {
return endId;
}
public void setEndId(int endId) {
this.endId = endId;
}
public String getDownLoadDir() {
return downLoadDir;
}
public void setDownLoadDir(String downLoadDir) {
this.downLoadDir = downLoadDir;
}
}
public void downLoadHtmls(DownLoadParams downLoadParams) {
HttpClient httpClient = new HttpClient();
long start = System.currentTimeMillis();
String url =downLoadParams.getUri();
for (int i = downLoadParams.getStartId(); i <= downLoadParams
.getEndId(); i++) {
try {
long startP = System.currentTimeMillis();
String currentUrl = url + i;
GetMethod getMethod = new GetMethod(currentUrl);
httpClient.executeMethod(getMethod);
saveFile(getMethod.getResponseBodyAsStream(),
downLoadParams.getDownLoadDir() + i + ".html");
long endP = System.currentTimeMillis();
log.info("waste" + (endP - startP) + "----rid" + i);
} catch (Exception e) {
log.error("exception" + e + "-->>" + i);
}
}
long end = System.currentTimeMillis();
log.info("waste over" + (end - start));
}
public static void saveFile(InputStream in, String filePath)
throws IOException {
File file = new File(filePath);
file.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
IOUtils.copy(in, fileOutputStream);
fileOutputStream.close();
in.close();
}
/**
* 数据量大使用,线程数根据cpu个数与网络决定,常规为cpu个数的倍数,可以测试使用,最少为4,
* @param downLoadParams
* @param threadCount
*/
public static void SpeedUpDownd(DownLoadParams downLoadParams,int threadCount){
class MultiProcess implements Runnable {
private DownLoadParams downLoadParams;
public void setDownLoadParams(DownLoadParams downLoadParams) {
this.downLoadParams = downLoadParams;
}
@Override
public void run() {
new SimpleDownLoadHtmlUtil().downLoadHtmls(downLoadParams);
}
}
int total = downLoadParams.endId-downLoadParams.startId+1;
ArrayBlockingQueue<Runnable> arrayQue = new ArrayBlockingQueue<Runnable>(
threadCount - 4);
ExecutorService service = new ThreadPoolExecutor(50, 50, 2,
TimeUnit.DAYS, arrayQue);
for (int i = 0; i <threadCount; i++) {
MultiProcess multiProcess=new MultiProcess();
DownLoadParams currentParams=new DownLoadParams();
currentParams.setStartId((total/threadCount)*i+1);
currentParams.setEndId((total/threadCount)*(i+1));
currentParams.setDownLoadDir(downLoadParams.getDownLoadDir());
currentParams.setUri(downLoadParams.getUri());
multiProcess.setDownLoadParams(currentParams);
service.execute(multiProcess);
}
service.shutdown();
}
}
分享到:
相关推荐
wget 下载工具 wget 下载工具 wget 下载工具 wget 下载工具
wget-1.11.4-1源代码
wget是Linux中的一个下载文件的工具, wget是在Linux下开发的开放源代码的软件,作者是Hrvoje Niksic,后来被移植到包括Windows在内的各个平台上。 它用在命令行下。 对于Linux用户是必不可少的工具, 尤其对于网络...
下载资源>把wget64.exe放置到C:\Windows\System32路径下>cmd 输入 wget64 下载链接地址
这里有官方代码有关wget-1.5.3至wget-1.16的全部当前最新代码,只为拿来分享与大家学习共进步。
wget下载 VS2008 代码
仅供学习使用
在wget的源代码中 src/url.c 这个文件中有wget如何处理文件名的函数url_file_name() url_file_name()在根据url的形式判断该保存为什么样的文件名,并进行了多方面的考虑,最终该函数调用了append_uri_pathel(),该...
wget命令行下载工具,支持在命令行下下载,等同于linux 下的wget命令。适合批处理下自动下载。
wget是一个从网络上自动下载文件的自由工具。它支持HTTP,HTTPS和FTP协议,可以使用HTTP代理. 所谓的自动下载是指,wget可以在用户退出系统的之后在后台执行。这意味这你可以登录系统,启动一个wget下载任务,然后...
windows下的wget下载工具!...这意味这你可以登录系统,启动一个wget下载任务,然后退出系统,wget将在后台执行直到任务完成,相对于其它大部分浏览器在下载大量数据时需要用户一直的参与,这省去了极大的麻烦。
网页下载工具,下载玩,解压缩直接使用就行了
wget命令rpm安装文件,需要预先安装rpm,才可以配置。
linux 离线安装wget
wget 是一个从网络上自动下载文件的自由工具,支持通过 HTTP、HTTPS、FTP 三个最常见的 TCP/IP协议 下载,并可以使用 HTTP 代理。"wget" 这个名称来源于 “World Wide Web” 与 “get” 的结合。所谓自动下载,是指 ...
GNU Wget2 2.0 增加了 HTTP2 上传,通过新的 -download-attr 选项支持 HTML5 下载属性,“Accept-Encoding: lzip”支持,各种选项以提高与 GNU Wget 的向后兼容性,在输出中支持终端超链接,以及其他大量的改进和...
windows wget.exe免费下载
wget 命令行下载工具, 支持https win10亲测, 下载https文件: https_wget 链接
wget的完整代碼
wget for ,通过CMD下载文件