找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 3088|回复: 0

自己动手编写MSDN下载工具

[复制链接]

307

主题

228

回帖

7335

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5585 个
贡献
253 次
宅之契约
0 份
在线时间
947 小时
注册时间
2014-1-25
发表于 2014-1-29 13:06:25 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
       微软msdn一般都会在vs安装包里提供,但是有时候你只需要庞大信息的一个小分支,特定信息只有微软官网才有,vs2010强大的帮助文档也未提供,我遇到这个问题的时候就想用java+jsoup做个下载器解决这个问题,按目录递归下载各个网页拼成整个的html,最后转换成doc。效果还是不错的,我另外生成目录并加到html最前端。我之所以要写这个代码,是因为前两天看到了windbg想看看用法无奈他的帮助信息指向到了微软msdn里,而vs没有这部分内容,仅在在线msdn才有。java代码如下:
  1. import java.io.FileOutputStream;
  2. import org.jsoup.Jsoup;
  3. import org.jsoup.nodes.Document;
  4. import org.jsoup.nodes.Element;
  5. import org.jsoup.select.Elements;
  6. public class MSDNDownloader
  7. {
  8.         public static String htmldirtree="";//生成目录树
  9.         public static String htmlbody="";//拼接章节
  10.         public static String urlbase="http://msdn.microsoft.com";//根路径地址
  11.         public static String root="/en-us/library/ff551063(v=vs.85).aspx";//windows debugging在msdn的根位置
  12.         public static int maxcount=10000;
  13.         public static void resolve(String cururl,int curdepth)
  14.         {
  15.                 boolean islastlayer=false;
  16.                 try
  17.                 {
  18.                         if(maxcount-- <= 0)
  19.                                 return;
  20.                         System.out.println(maxcount);
  21.                         Document doc=Jsoup.connect(cururl).timeout(0).get();
  22.                         if(!doc.select("div.toclevel2.current a").isEmpty())
  23.                                 islastlayer=true;
  24.                         //先添加当前层目录
  25.                         Element curtitle;
  26.                         if(islastlayer)
  27.                                 curtitle=doc.select("div.toclevel2.current a").get(0);
  28.                         else
  29.                                 curtitle=doc.select("div.toclevel1.current a").get(0);
  30.                         htmldirtree+= "<H"+curdepth+" style="margin-left:"+20*curdepth+"px">";
  31.                         htmldirtree+= curtitle.text()+"</H"+curdepth+">\n";
  32.                         System.out.println(curtitle.text());
  33.                         //再添加当前层内容
  34.                         htmlbody += doc.select(".topic").toString()+"\n";
  35.                        
  36.                         if(!islastlayer)
  37.                         {
  38.                                 //处理下一层
  39.                                 Elements subtitle=doc.select("div.toclevel2 a");
  40.                                 if(!doc.select("div.toclevel2.current a").isEmpty())
  41.                                 {
  42.                                         subtitle.remove(0);
  43.                                 }
  44.                                 for(Element everytitle:subtitle)
  45.                                 {
  46.                                         resolve(everytitle.attr("abs:href"),curdepth+1);
  47.                                 }     
  48.                         }
  49.                 }
  50.                 catch(Exception exc)
  51.                 {
  52.                         System.out.println("错误!");
  53.                         //System.exit(0);
  54.                 }
  55.         }
  56.         public static void main(String[] args)
  57.         {
  58.                 try
  59.                 {
  60.                         resolve(urlbase+root,1);
  61.                        
  62.                         FileOutputStream fs=new FileOutputStream("result.htm");
  63.                         String html="<!DOCTYPE html>\n<html>\n<head><title>result</title></head>\n<body>\n<font color=0x00ffff>\n";
  64.                         html += htmldirtree+"\n</font>\n"+htmlbody+"\n</body>\n</html>";
  65.                         fs.write(html.getBytes());
  66.                         fs.close();
  67.                 }
  68.                 catch(Exception exc)
  69.                 {
  70.                         System.out.println("错误!");
  71.                         System.exit(0);
  72.                 }
  73.         }
  74. }
复制代码

以上代码比较厉害,不过由于手机网络限制始终没有直接运行,我找仅仅了一个子目录运行,就生成了5M的html(见过这么大的没),
以下是部分目录:
Debugger Reference
Command-Line Options
CDB Command-Line Options
KD Command-Line Options
WinDbg Command-Line Options
DbgSrv Command-Line Options
KdSrv Command-Line Options
DbEngPrx Command-Line Options
KDbgCtrl Command-Line Options
DbgRpc Command-Line Options
SymStore Command-Line Options
Environment Variables
General Environment Variables
Kernel-Mode Environment Variables
Debugger Commands


回复

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-4-19 19:31 , Processed in 0.042174 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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