51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1803|回复: 2
打印 上一主题 下一主题

[求助] 分享国外的一批性能测试资料(附自动下载程序)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2013-3-5 11:50:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
今天在微博上看到陈能技共享的一批性能测试资料,很不错的,分享链接给同行们。

链接如下:http://www.perftestplus.com/resources/

由于资料很多,手动下载很麻烦,所以特地写了一段自动下载程序,也一并分享之。这段代码大家改吧改吧去下载任何网页上的价格资源都是可以的。


  1. package com.qiang.misc;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.OutputStream;
  8. import java.net.HttpURLConnection;
  9. import java.net.URL;
  10. import java.util.ArrayList;
  11. import java.util.List;

  12. public class PerfTestPDFDownload {
  13. public static void main(String[] args) {
  14.   PerfTestPDFDownload ptDownload = new PerfTestPDFDownload();
  15.   String response = ptDownload.doRequest("http://www.perftestplus.com/resources/");
  16.   List<String> al = ptDownload.doSearch(response, "<li><a href=\"", "\">");
  17.   for (int i=1; i<al.size(); i++) {
  18.    String pdfSource = "http://www.perftestplus.com/resources/" + al.get(i);
  19.    ptDownload.doDownload(pdfSource, "E:\\51Testing\\LoadRunner\\PerfTestPlus\\" + al.get(i));
  20.   }
  21. }

  22. public String doRequest(String src) {
  23.   String response = "", line = "";
  24.   try {
  25.    URL url = new URL(src);
  26.    HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
  27.    
  28.    urlConnection.setUseCaches(false);
  29.    urlConnection.connect();
  30.    
  31.    BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "GBK"));
  32.    while ((line = in.readLine())!= null) {
  33.     response += line + "\n";
  34.    }
  35.   }
  36.   catch (Exception e) {
  37.    e.printStackTrace();
  38.   }
  39.   return response;
  40. }

  41. public List<String> doSearch(String source, String left, String right) {
  42.   int posLeft, posRight, tempLeft;
  43.   String tempSource, result;
  44.   List<String> list = new ArrayList<String>();
  45.   int leftLen = left.length();
  46.   int rightLen = right.length();
  47.   
  48.   try {
  49.    source = source.substring(source.indexOf(left), source.lastIndexOf(right)+rightLen+1);
  50.    while (((posLeft = source.indexOf(left)) >= 0) && ((posRight = source.indexOf(right)) >= 0)) {
  51.     tempSource = source.substring(0, posRight);
  52.     tempLeft = tempSource.lastIndexOf(left);
  53.     result = tempSource.substring(tempLeft+leftLen);
  54.     list.add(result);
  55.     source = source.substring(posRight+rightLen);
  56.    }
  57.   }
  58.   catch (Exception e) {
  59.    e.printStackTrace();
  60.   }
  61.   return list;
  62. }

  63. public int doDownload(String src, String path) {
  64.   int dlstatus;
  65.   try {
  66.    URL url = new URL(src);
  67.    File outFile = new File(path);
  68.    HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
  69.    urlConnection.setUseCaches(false);
  70.    urlConnection.setReadTimeout(20000);
  71.    urlConnection.connect();
  72.    if (urlConnection.getResponseCode() >= 400)
  73.     dlstatus = urlConnection.getResponseCode();
  74.    else {
  75.     OutputStream os = new FileOutputStream(outFile);
  76.     InputStream is = urlConnection.getInputStream();
  77.     byte[] buff = new byte[1024];
  78.     while(true) {
  79.      int readed = is.read(buff);
  80.      if(readed == -1) {
  81.       break;
  82.      }
  83.      byte[] temp = new byte[readed];
  84.      System.arraycopy(buff, 0, temp, 0, readed);
  85.      os.write(temp);
  86.     }
  87.     is.close();
  88.           os.close();
  89.           dlstatus = 200;
  90.    }
  91.    urlConnection.disconnect();
  92.   }
  93.   catch (Exception e) {
  94.    dlstatus = 999;
  95.   }
  96.   return dlstatus;
  97. }
  98. }

复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2013-3-5 11:59:29 | 只看该作者
高手都是自己写代码下载的,我只能打开迅雷下载所有链接了。。。。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2013-3-5 13:36:38 | 只看该作者
写写更健康。。。。。。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-9-23 03:21 , Processed in 0.091814 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表