备份CSDN博客——dump到本地存档/博客搬家

来源:互联网 发布:绘图纸用什么软件 编辑:程序博客网 时间:2024/06/01 19:26

由于学习过程做笔记,CSDN上记录了好多博客,真担心某一天被封了,再也打不开自己的博客了,于是本文就记录下如何备份博客。

有两种方式:

1.博客搬家——将博客内所有文章都复制到其他网站。以下博客都支持相互搬家。用了开源中国、ITEYE、51CTO的搬家。ITEYE成功率最高,可能是ITEYE和CSDN有合作的关系把。开源中国成功率低,超过100篇就要操作好多次;51CTO走批量方式,等了2天还没看到结果;博客园限制搬家时间,下班时间和周末才能搬家。推荐ITEYE先备份一个,博客园在备份一个,毕竟博客园的UI最简洁大方。



2.dump到本地:

以下转载一片博文,末尾有源码下载,本地debug改了下,30多篇长文,1G大小的都完整下载成功了。以下博文源码有点bug,可能是htmlparser.jar版本更新引起。htmlparser.jar是一个爬虫工具包。

源代码里面部分写死了csdn域名,想dump其他博客请replace掉所有域名。


大哥有了新想法,然而没有技术,令人欣慰的是大哥想到了我,于是我便答应免费帮个忙,这是一个基于云的项目,具体细节也就不透露了,然而在实现的过程中,其中一个模块我觉得可以自用,于是我就想把这个模块抽出来,该模块的功能就是将CSDN博客上的文章下载到本地。

        假期只完成了一个模板,虽然很垃圾,但是却能满足自用的需求,一直以来,我都很害怕自己喝懵了写的一些感悟放在网上会在某一天再也打不开,事实上,这种事 情确实也发生过很多次。忘记用户,文章被管理员删除,博客被封闭,网站不再维护等都会导致这样的问题,于是我就不得不定期将自己在各个网站注册的博客复制 到一个本地的文档上,包括网易的,百度的,CSDN的,51CTO的,以及老婆的QQ空间的(我总是将内容发布在老婆的QQ上,因为那上面可以畅所欲 言),这么多的网站,如此多的日志,工作量真的不少,久而久之,本地的存档也越来越乱,渐渐的,有很多文章都被遗漏了。特别是CSDN的博客,一直以来, 我都想将其完整的dump到本地,一篇一篇的复制,简直不可能,因为太多了,也找过整站下载器,但是效果不理想。趁此机会,别人委托我做的这个小玩意正好 可以用于此目的,而且比较满意的一点就是dump下来的每一篇文章都裁掉了不相关的内容,比如友情链接,博客访问量以及广告等,唯一被保留的就是正文和正 文的图片资源。
        起初我是使用C++手工实现的,然而却需要自行解析HTML文档的各个标签,落实下来就是复杂的字符串解析,其实字符串解析可以堪称是编程的精髓,但是对 于实际做项目,这种工作还是直接使用现有的解析库比较好,后来我发现使用脚本语言更简单,比如使用python,perl,甚至grep/awk/sed 都可以,然而字符编码却始终是一个大问题。通过咨询一个超猛的同事,我认识了htmlparser这个java库,实在是太方便了,它将html文件元素 抽象成了各个类,这样可以很方便的实现过滤,更可贵的是,这种过滤甚至都不用自己实现,htmlparser中自带了过滤功能,你要做的只是重载一些方法 即可,这样就是使用很简单的代码实现这个博客下载功能了,下载完了之后最好将其保存成一个单独的PDF文档,虽然java也可以实现这个功能,然而目前已 经有了很多这样的工具,有现成工具的就不编程实现,这永远是一个真理。
        首先看一下效果,然后看一下代码。
        保存在本地的存档拥有下面的目录结构,首先是一个顶级目录,以我博客的标题来命名,内部是一个按月份存档的目录集合以及一个index.html索引文件,如下图所示:
 
 

展开一个月份存档目录,你将看到本月的文章集合,每一篇文章包含一个目录,如下图所示:


每一篇文章包含的目录中保存有该篇文章包含的所有图片,如果没有包含图片,则目录为空,如下图:
 

随意打开一篇文章,你将看到该篇文章的标题以及正文,所有的图片也被包含,链接到了该文章的_files目录中的对应图片,如下图:


 
 

index.html呈现处以下的样子:


点击每一篇,将跳转到该篇文章
如果你以文本编辑器或者xcode打开每一篇文章或者index.html文件,你将看到其中的大部分链接都被改成了本地的相对路径了,并且删除了大量的无关的内容,这种修改很简单,手工改其实很可以做到,使用程序来做当然更简便些,问题是当你写程序所带来的麻烦超过了手工修改的麻烦时,这种编程就很没有意义,幸运的是,htmlparser可以很简单的做到这一点,一点也不复杂,这样的话这种编程就显得很有意义了。
        代码很简单,基本就是几大块:
1.几次遍历-按主页遍历月份信息,按月份存档遍历文章,按每一篇文章遍历图片;
2.解析关键信息,比如标题,文章中的图片等,并填充数据结构。这种事可以通过Filter来完成;
3.根据filter的副作用填充的信息生成目录。

需要说明的是,以下的代码完全是过程化的,没有使用Java语言的OO特性,因此它的数据以及方法完全是static的,没有生成任何对象,我只是想使用htmlparser的API以及java语言IDE的诸多良好的功能,比如方法以及方法参数的自动补全功能,老手或者科班高年级学生可能会较真地说,C/C++的IDE也可以支持这样的功能,如果碰到这样反驳的,我也可以说,其实嘛,汇编语言也是可以自动补全的…另外,代码中有很多的硬编码,其实应该将它们再抽象一下的,或者说定义成变量也可以,只是因为自用,以后也不准备维护,就这么着了。还有,那就是最大的问题,代码有一些bug,比如对于标题中含有奇怪字符的支持,以及错误日志(这很重要)的记录的缺失等等。不管怎么说,代码如下:

[java] view plain copy
  1. <span style="font-family:KaiTi_GB2312;font-size:18px;">import  org.htmlparser.Node;  
  2. import  org.htmlparser.NodeFilter;  
  3. import  org.htmlparser.Parser;  
  4. import  org.htmlparser.filters.TagNameFilter;  
  5. import  org.htmlparser.util.NodeList;  
  6. import org.htmlparser.tags.*;  
  7. import java.io.*;  
  8. import java.net.*;  
  9. import java.nio.*;  
  10. import java.util.List;  
  11. import javax.management.*;  
  12. /* 类名使用test很不规范,然而为了方面胡乱起的名字,可是不管怎么说,它确实是个test */  
  13. public class  test {  
  14.     /* 月份文章的月份名称/月份存档URL对的列表 */  
  15.     final static AttributeList indexList = new AttributeList();  
  16.     /* 每月文章名称/每月文章的URL对的列表 */  
  17.     final static AttributeList articleList = new AttributeList();  
  18.     /* 每篇文章图片本地存档地址/每篇文章图片URL对的列表 */  
  19.     final static AttributeList resourceList = new AttributeList();  
  20.     /* 保存月份以及该月文章本地存档的列表,用于生成目录 */  
  21.     static AttributeList monthList = new AttributeList();  
  22.     /* 用于生成本地存档目录的writer */  
  23.     static OutputStreamWriter index_handle = null;  
  24.     static String proxy_addr = null;  
  25.     static int proxy_port = 3128;  
  26.     /* 
  27.     * @param url 网页的URL 
  28.     * @param type 类型:1为文本,0为二进制 
  29.     * @return 内容的字节数组 
  30.     */  
  31.     public static byte[] GetContent(String url, int type) {  
  32.         byte ret[] = null;  
  33.         try  {  
  34.             HttpURLConnection conn = null;  
  35.             InputStream urlStream = null;;  
  36.             URL surl = new  URL(url);  
  37.             int j = -1;  
  38.             if (proxy_addr != null) {  
  39.                 InetSocketAddress soA = new InetSocketAddress(InetAddress.getByName(proxy_addr), proxy_port);  
  40.                 Proxy proxy = new Proxy(Proxy.Type.HTTP, soA);  
  41.                 conn =  (HttpURLConnection) surl.openConnection(proxy);  
  42.             } else {                
  43.                 conn =  (HttpURLConnection) surl.openConnection();  
  44.             }  
  45.             /* 必须加上这一句伪装成Mozilla浏览器,否则CSDN会拒绝连接 */  
  46.             conn.setRequestProperty( "User-Agent","Mozilla/4.0");   
  47.             conn.connect();  
  48.             urlStream = conn.getInputStream();  
  49.             if (type == 1) {  
  50.                 String sTotalString = "";  
  51.                 BufferedReader reader =  new  BufferedReader(new  InputStreamReader(urlStream, "UTF-8"));  
  52.    
  53.                 CharBuffer vv = CharBuffer.allocate(1024);  
  54.                 while ((j = reader.read(vv.array())) != -1) {  
  55.                     sTotalString += new String(vv.array(), 0, j);            
  56.                     vv.clear();  
  57.                 }  
  58.                 sTotalString = sTotalString.replace('\n'' ');   
  59.                 sTotalString = sTotalString.replace('\r'' ');  
  60.                 ret = sTotalString.getBytes();  
  61.             } else {  
  62.                 ByteBuffer vv = ByteBuffer.allocate(1024);  
  63.                 /* CSDN允许最大图片有上限 */  
  64.                 ByteBuffer buffer = ByteBuffer.allocate(5000000);  
  65.                 while ((j = urlStream.read(vv.array())) != -1)   {   
  66.                     buffer.put(vv.array(), 0, j);  
  67.                     vv.clear();  
  68.                 }   
  69.                 ret = buffer.array();  
  70.             }  
  71.         }catch (Exception e){  
  72.             e.printStackTrace();  
  73.             //追加出错日志  
  74.         }   
  75.         return ret;  
  76.     }  
  77.     /* 
  78.     * @param path 文件路径 
  79.     * @param content 文件内容的字节数组 
  80.     * @return 成功或者失败 
  81.     */  
  82.     public static boolean WriteFile(String path, byte[] content) {  
  83.         try {  
  84.             FileOutputStream osw = new FileOutputStream(path);  
  85.             osw.write(content);    
  86.             osw.close();  
  87.         } catch  (Exception e) {  
  88.             e.printStackTrace();  
  89.             //追加出错日志  
  90.             return false;  
  91.         }  
  92.         return true;  
  93.     }  
  94.     /* 
  95.     * @param path 目录路径 
  96.     * @return 成功或者失败 
  97.     */  
  98.     public static boolean MKDir(String path) {  
  99.         try {         
  100.             File fp = new File(path);  
  101.             if(!fp.exists()) {  
  102.                 fp.mkdir();  
  103.             }  
  104.         } catch(Exception e) {  
  105.             e.printStackTrace();  
  106.             //追加出错日志  
  107.             return false;  
  108.         }  
  109.         return true;  
  110.     }  
  111.     /* 
  112.     * @param path 文件路径 
  113.     * @param url 文章在blog上的URL 
  114.     * @param articles 保存本月存档的列表 
  115.     * @return 无 
  116.     */  
  117.     public static void HandleHtml(String path, String url, AttributeList articles) {  
  118.         try {           
  119.             StringBuffer text = new  StringBuffer();  
  120.             NodeList nodes = HandleText(new String(GetContent(url, 1)), 3);  
  121.             Node node = nodes.elementAt(0);  
  122.             String title = (String)((List<Attribute>)resourceList.asList()).get(0).getValue();  
  123.                   
  124.             String filepath=path+"/"+title;  
  125.             List<Attribute> li = resourceList.asList();  
  126.             /* 加入meta信息 */  
  127.             text.append( new  String("<meta http-equiv=\"Content-Type\" content=\"text/html; chaset=utf-8\"/>"));  
  128.             text.append("<h1>"+title+"</h1>");                    
  129.             if (node != null) {  
  130.                 Div dv = (Div)node;   
  131.                 text.append( new  String(dv.toHtml().getBytes("UTF-8"), "UTF-8"));  
  132.             } else {  
  133.                 text.append("<h3>Download error</h3>");  
  134.             }  
  135.       
  136.             test.MKDir(filepath+"_files");   
  137.             articles.add(new Attribute(filepath.split("/"2)[1], title));                 
  138.                   
  139.             for (int i = 1; i< li.size(); i ++) {  
  140.                 byte[] imgString = GetContent((String)li.get(i).getValue(), 0);  
  141.                 test.WriteFile(filepath+"_files/"+li.get(i).getName()+".gif", imgString);  
  142.             }  
  143.             resourceList.clear();  
  144.             test.WriteFile(filepath+".html", text.toString().getBytes());  
  145.         }  catch  (Exception e) {  
  146.             //追加出错日志  
  147.             e.printStackTrace();  
  148.         }   
  149.     }  
  150.     /* 
  151.     * @param nlist HTML正文的子标签链表 
  152.     * @param index 用于索引图片的个数以及当前的图片数 
  153.     * @return 当前的图片数 
  154.     */  
  155.     public static int parseImg(NodeList nlist, int index) {  
  156.         Node img = null;  
  157.         int count = nlist.size();  
  158.         for (int i = 0; i < count; i++) {  
  159.             img = nlist.elementAt(i);  
  160.             if (img instanceof ImageTag ) {  
  161.                 ImageTag imgtag = (ImageTag)img;  
  162.                 if (!imgtag.isEndTag()) {  
  163.                     String title = (String)((List<Attribute>)resourceList.asList()).get(0).getValue();  
  164.                     /* 将图片的URL映射成本地路径 */  
  165.                     resourceList.add(new Attribute(""+index, new String(imgtag.extractImageLocn().getBytes())));  
  166.                     title = title.trim();  
  167.                     imgtag.setImageURL(title+"_files/"+index+".gif");  
  168.                     /* 递增本地路径序列 */  
  169.                     index++;  
  170.                 }  
  171.             } else {  
  172.                 NodeList slist = img.getChildren();  
  173.                 if (slist != null && slist.size() > 0) {  
  174.                     index = test.parseImg(slist, index);  
  175.                 }  
  176.             }  
  177.         }  
  178.         return index;  
  179.     }  
  180.     /* 
  181.     * @param nlist HTML月份存档的子标签链表 
  182.     * @param index 无用 
  183.     * @return 无用 
  184.     */  
  185.     public static int parseMonthArticle(NodeList nlist, int index) {  
  186.         Node atls = null;  
  187.         int count = nlist.size();  
  188.         for (int i = 0; i < count; i++) {  
  189.             atls = nlist.elementAt(i);  
  190.             if (atls instanceof LinkTag ) {  
  191.                 LinkTag link = (LinkTag)atls;  
  192.                 indexList.add(new Attribute(link.getLinkText(), link.extractLink()));  
  193.             } else {  
  194.                 NodeList slist = atls.getChildren();  
  195.                 if (slist != null && slist.size() > 0) {  
  196.                     index = test.parseMonthArticle(slist, index);  
  197.                 }  
  198.             }  
  199.         }  
  200.         return index;  
  201.     }  
  202.     /* 
  203.     * @param nlist HTML标题的子标签链表 
  204.     * @param index 无用 
  205.     * @return 无用 
  206.     */  
  207.     public static int parseTitle(NodeList nlist, int index) {  
  208.         Node tit = null;  
  209.         int count = nlist.size();  
  210.         for (int i = 0; i < count; i++) {  
  211.             tit = nlist.elementAt(i);  
  212.             if (tit instanceof Span ) {  
  213.                 Span span = (Span)tit;                                                 
  214.                 if (span.getAttribute("class") != null && span.getAttribute("class").equalsIgnoreCase("link_title")) {  
  215.                     LinkTag link = (LinkTag)span.childAt(0);  
  216.                     String title = link.getLinkText();  
  217.                     /* 将文件名中不允许的字符替换成允许的字符 */  
  218.                     title = title.replace('/''-');  
  219.                     title = title.trim();  
  220.                     title = title.replace(' ''-');  
  221.                     resourceList.add(new Attribute("title", title));  
  222.                 }  
  223.             } else {  
  224.                 NodeList slist = tit.getChildren();  
  225.                 if (slist != null && slist.size() > 0) {  
  226.                     index = test.parseTitle(slist, index);  
  227.                 }  
  228.             }  
  229.         }  
  230.         return index;  
  231.     }  
  232.     /* 
  233.     * @param nlist HTML每月份存档的子标签链表 
  234.     * @param index 无用 
  235.     * @return 无用 
  236.     */  
  237.     public static int parsePerArticle(NodeList nlist, int index) {  
  238.         Node atl = null;  
  239.         int count = nlist.size();  
  240.         for (int i = 0; i < count; i++) {  
  241.             atl = nlist.elementAt(i);  
  242.             if (atl instanceof Span ) {  
  243.                 Span span = (Span)atl;  
  244.                 if (span.getAttribute("class") != null && span.getAttribute("class").equalsIgnoreCase("link_title")) {  
  245.                     LinkTag link = (LinkTag)span.childAt(0);  
  246.                     articleList.add(new Attribute(link.getLinkText(), "http://blog.csdn.net"+link.extractLink()));  
  247.                 }  
  248.             } else {  
  249.                 NodeList slist = atl.getChildren();  
  250.                 if (slist != null && slist.size() > 0) {  
  251.                     index = test.parsePerArticle(slist, index);  
  252.                 }  
  253.             }  
  254.         }  
  255.         return index;  
  256.     }  
  257.     /* 
  258.     * @param nlist HTML分页显示标签的子标签链表 
  259.     * @param index 无用 
  260.     * @return 无用 
  261.     */  
  262.     public static int parsePage(NodeList nlist, int index) {  
  263.         Node pg = null;  
  264.         int count = nlist.size();  
  265.         for (int i = 0; i < count; i++) {  
  266.             pg = nlist.elementAt(i);  
  267.             if (pg instanceof LinkTag ) {  
  268.                 LinkTag lt = (LinkTag)pg;  
  269.                 if (lt.getLinkText().equalsIgnoreCase("下一页")) {  
  270.                     try {  
  271.                         test.HandleText(new String(test.GetContent("http://blog.csdn.net"+lt.extractLink(), 1)), 2);  
  272.                     } catch (Exception e) {  
  273.                         //追加出错日志  
  274.                     }  
  275.                 }  
  276.             }  
  277.         }  
  278.         return index;  
  279.     }  
  280.     /* 
  281.     * @param nlist HTML作者信息标签的子标签链表 
  282.     * @param index 无用 
  283.     * @return 无用 
  284.     */  
  285.     public static int parseAuthor(NodeList nlist, int index) {  
  286.         Node aut = null;  
  287.         int count = nlist.size();  
  288.         for (int i = 0; i < count; i++) {  
  289.             aut = nlist.elementAt(i);  
  290.             if (aut instanceof LinkTag ) {  
  291.                 LinkTag link = (LinkTag)aut;  
  292.                 resourceList.add(new Attribute("author", link.getLinkText()));  
  293.             } else {  
  294.                 NodeList slist = aut.getChildren();  
  295.                 if (slist != null && slist.size() > 0) {  
  296.                     index = test.parseAuthor(slist, index);  
  297.                 }  
  298.             }  
  299.         }  
  300.         return index;  
  301.     }  
  302.     /* 
  303.     * @param input 输入的html文档字符串 
  304.     * @param skip 是否执行的类别 
  305.     * @return 匹配的链表,很多类别通过副作用而起作用 
  306.     */  
  307.     public static  NodeList HandleText(String input, final int skip)  throws  Exception {  
  308.         Parser parser = Parser.createParser(input,  "UTF-8" );  
  309.         NodeList nodes = parser.extractAllNodesThatMatch(new  NodeFilter() {  
  310.             public boolean accept(Node node) {  
  311.                 if (node instanceof Div) {  
  312.                     Div dv = (Div)node;  
  313.                     NodeList nlist = dv.getChildren();  
  314.                     if(dv.getAttribute("id") != null && nlist != null) {  
  315.                         if(dv.getAttribute("id").equalsIgnoreCase("article_content")  && skip == 3) {  
  316.                             parseImg(nlist, 0);  
  317.                             return   true ;  
  318.                         } else if (dv.getAttribute("id").equalsIgnoreCase("article_details") && skip == 3) {  
  319.                             parseTitle(nlist, 0);  
  320.                         } else if (dv.getAttribute("id").equalsIgnoreCase("archive_list") && (skip == 1 || skip == 4)) {  
  321.                             parseMonthArticle(nlist, 0);  
  322.                         } else if (dv.getAttribute("id").equalsIgnoreCase("papelist") && skip == 2) {  
  323.                             parsePage(nlist, 0);  
  324.                         } else if (dv.getAttribute("id").equalsIgnoreCase("blog_title") && skip == 4) {  
  325.                             parseAuthor(nlist, 0);  
  326.                         }  
  327.                     }  
  328.                     if (dv.getAttribute("class") != null && nlist != null) {  
  329.                         if (dv.getAttribute("class").equalsIgnoreCase("article_title") && skip == 2) {  
  330.                             parsePerArticle(nlist, 0);  
  331.                         }  
  332.                     }  
  333.                 }    
  334.                 return false;  
  335.             }  
  336.         });  
  337.         return nodes;  
  338.     }  
  339.     /* 
  340.     * @param filepath 本地存档的路径 
  341.     * @param url 保存本月存档的网页的URL 
  342.     * @param articles 保存本月存档的链表 
  343.     * @return 无 
  344.     */  
  345.     public static void parseMonth(String filepath, String url, AttributeList articles) {  
  346.         List<Attribute> li = articleList.asList();  
  347.         try  {  
  348.             HandleText(new String(GetContent(url, 1)), 2);  
  349.         }catch (Exception e){  
  350.             //追加出错日志  
  351.         }  
  352.         test.MKDir(filepath);  
  353.         for (int i = 0; i < li.size(); i++) {  
  354.             HandleHtml(filepath, (String)li.get(i).getValue(), articles);  
  355.             try {  
  356.                 /* 慢一点,否则会被认为是恶意行为 */  
  357.                 Thread.sleep(500);  
  358.             } catch (Exception e) {}  
  359.         }  
  360.         articleList.clear();  
  361.     }  
  362.     /* 
  363.     * @param url blog入口文章的URL 
  364.     * @return 无 
  365.     */  
  366.     public static void parseAll(String url) {  
  367.         try  {   
  368.             String author = null;  
  369.             HandleText(new String(GetContent(url, 1)), 4);   
  370.   
  371.             author = (String)((List<Attribute>)resourceList.asList()).get(0).getValue();  
  372.             resourceList.clear();  
  373.             test.MKDir(author);  
  374.             List<Attribute> li = indexList.asList();  
  375.             for (int i = 0; i < li.size(); i++) {                           
  376.                 AttributeList articles = new AttributeList();  
  377.                 monthList.add(new Attribute(li.get(i).getName(), articles));  
  378.                 parseMonth(author + "/" + li.get(i).getName(), (String)li.get(i).getValue(), articles);                       
  379.             }  
  380.             HandleIndex(author);  
  381.         }catch (Exception e){  
  382.             e.printStackTrace();  
  383.         }  
  384.         indexList.clear();  
  385.     }  
  386.     /* 
  387.     * @param dir 本地存档根路径名称 
  388.     * @return 无 
  389.     */  
  390.     static void HandleIndex(String dir) {  
  391.         try  {  
  392.             index_handle = new OutputStreamWriter(new FileOutputStream(dir + "/index.html"), "GB18030");  
  393.             String header = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>CSDN文章归档</title></head><body bgcolor=\"white\" text=\"black\" link=\"#0000FF\" vlink=\"#840084\" alink=\"#0000FF\"><hr></div><div><h1 class=\"title\"><a name=\"id2747881\"></a>"+dir+"CSDN文章归档</h1></div></div><hr></div><div class=\"toc\"><p><b>目录</b></p><dl><dt><span class=\"preface\"><a href=\"preface.html\">摘要</a></span></dt>";  
  394.             String tailer = "</div></div><hr></body></html>" ;  
  395.             index_handle.write(header);  
  396.                                   
  397.             List<Attribute> li = monthList.asList();  
  398.             for (int i = 0; i < li.size(); i++) {  
  399.                 String mindex = "<dt><span class=\"part\"><h4>"+li.get(i).getName()+"</span></dt><dd><dl>";  
  400.                 AttributeList articles = (AttributeList)li.get(i).getValue();  
  401.                 List<Attribute> al = articles.asList();  
  402.                 index_handle.write(mindex);  
  403.                 for (int j = 0; j < al.size(); j++) {  
  404.                     String per = "<dt><span class=\"part\"><a href=\""+al.get(j).getName()+".html\">"+al.get(j).getValue()+"</a></span></dt>";  
  405.                     index_handle.write(per);  
  406.                 }  
  407.                 index_handle.write("</dl></dd>");                                      
  408.             }  
  409.             index_handle.write(tailer);  
  410.             index_handle.close();  
  411.         }catch (Exception e){ }  
  412.     }  
  413.     /* 
  414.     * @param args args[0]:blog入口文章的URL args[1]:代理地址 args[2]:代理端口 【用法:java DownBlog http://blog.csdn.net/dog250 192.168.40.199 808】 
  415.     * @return 无 
  416.     */  
  417.     public static void main(String[] args)  throws  Exception {  
  418.         parseAll("http://blog.csdn.net/dog250");  
  419.         /*boolean valid = false; 
  420.         if (args.length == 1) { 
  421.             valid = true; 
  422.         } else if (args.length == 2) { 
  423.             proxy_addr = args[1]; 
  424.             valid = true; 
  425.         } else if (args.length == 3) { 
  426.             proxy_addr = args[1]; 
  427.             proxy_port = Integer.parseInt(args[2]); 
  428.             valid = true; 
  429.         }  
  430.         if (valid) { 
  431.             parseAll(args[0]); 
  432.         } else { 
  433.              
  434.         }*/  
  435.     }  
  436. }</span>  

那么,如果使用上面的代码备份你自己的CSDN博客呢?很简单,将dog250改成你的ID即可,我在main方法中注释了一大段的内容,你也可以将其展开,然后他就是通用的了,试试看。



http://download.csdn.net/detail/truelove12358/9877519



原创粉丝点击