public class 代码分析 {     public static void main(String[] args) throws Exception {
          Matcher ma;
          String caricatureUrl, caricatureName, html, picUrl, temp, temp1;
          StringBuffer sb;
          Pattern pa;
          int book_1, book_2, i, j;
          System.out.println("分析地址是:http://www.kkkmh.com/manhua/0503/jie-jie-shi.html");
          html = getOneHtml("http://www.kkkmh.com/manhua/0503/jie-jie-shi.html");
//          <li><a href="/manhua/0503/151/3051.html" title="结界师 第1本" target="_blank">第1本</a></li>
          pa = Pattern.compile("<li><a href=\"/manhua/(.*?) title=(.*?)target=\"_blank\">(.*?)</a></li>", Pattern.DOTALL);
          ma = pa.matcher(html);
          while (ma.find()) {
               temp1 = ma.group();
               temp = "target=\"_blank\">";
               book_2 = temp.length();
               book_1 = temp1.indexOf(temp) + temp.length();
               book_2 = temp1.indexOf("<", book_1);
               caricatureName = temp1.substring(book_1, book_2);
               temp = "<li><a href=\"";
               book_1 = temp.length();
               book_2 = temp1.indexOf("\"", book_1);
               caricatureUrl = "http://www.kkkmh.com" + temp1.substring(book_1, book_2);
               System.out.println("[" + caricatureName + "]" + caricatureUrl);
          }
          System.out.println("分析地址是:http://www.kkkmh.com/manhua/0503/151/29376.html");
          html = getOneHtml("http://www.kkkmh.com/manhua/0503/151/29376.html");
//          pic[0] = '2f636f6d696364617465322f636f6d6963616263642f652d682f6a6a732f7462702f3030316c7763796b62632e706e67';
          pa = Pattern.compile("pic\\W(\\d.*?)\\W(.*?);", Pattern.DOTALL);
          ma = pa.matcher(html);
          while (ma.find()) {
               System.out.println(ma.group());
               temp = ma.group();
               sb = new StringBuffer(temp.substring(temp.indexOf("'")).replaceAll("'", "").replaceAll(";", "").trim());
               j = sb.length() / 2;
               for (i = 0; i < j; i++) {
                    sb.insert(i * 3, "%");
               }
               picUrl = URLDecoder.decode(sb.toString(), "UTF-8");
               System.out.println("http://mhc1.kkkmh.com" + picUrl);
          }
     }
     private static String getOneHtml(String htmlurl) throws Exception {
          URL url;
          String temp;
          StringBuffer sb = new StringBuffer();
          url = new URL(htmlurl);
          BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
          while ((temp = in.readLine()) != null) {
               sb.append(temp);
          }
          in.close();
          return sb.toString();
     }
}
我要简化的就是代码转换问题,我现在用循环解决,还有更好的办法吗?
               for (i = 0; i < j; i++) {
                    sb.insert(i * 3, "%");
               }
               picUrl = URLDecoder.decode(sb.toString(), "UTF-8");
现在就是用循环每隔两个字符+一个%,再转回正确地址.