[源码]打包下载算法与数据结构演示动画
很早的时候,学习数据结构的时候。收集了一下演示的动画。帮助理解。但是不全。今天在看KMP算法的时候。看到了福州大学的一个精品课程。。81个演示动画呢。。想打包下载收藏。话说福州大学这才是好样的。踏踏实实搞学术。
第一种方法就是手工了。。嘎嘎。你敢么。一个个下载。。。一个个改名。。
第二种就是用整站下载的软件了。。但是我看了一下swf的命名。我就知道下载下来意义不大。因为名字不好理解。
第三种就是自己写个程序吧。。
整体思路,首先访问课程页面,解析得到每一章的标题和内容,然后创立章节文件夹,得到每个动画对应的html页面,然后对html页面解析,提取swf地址。然后下载就行了。
比较疼的地方是那个页面用的是gb2312编码。而解析神器HtmlAgilityPack,不能指定编码。只能想办法绕过了。
WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(url)); HtmlDocument doc = new HtmlDocument(); doc.Load(ms, Encoding.GetEncoding("gb2312"));
绕过方法就是先使用内置类得到内存流。然后从内存中加载。
然后呢。涉及的技术就是xpath了。参考着xpath的文档。搞定了不少。中间还有一个地方就是我没注意看。这个页面有两个文件是一样名字。。调试了几次才发现。。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using HtmlAgilityPack; using System.IO; using System.Threading; using System.Net; namespace FzuSwf { class Program { static void Main(string[] args) { DoWork(); } //执行任务 static void DoWork() { HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load("http://ds.fzu.edu.cn/fine/resources/"); HtmlNode divResource = doc.GetElementbyId("divResource"); foreach (HtmlNode child in divResource.ChildNodes) { if (child.Name == "table") { HtmlNode ptile = child.SelectSingleNode("tr[1]"); Directory.CreateDirectory(ptile.InnerText.Trim()); int i = 0; HtmlNodeCollection pcontents = child.SelectNodes("tr[position()>1]"); Console.WriteLine(ptile.InnerText.Trim()); foreach (HtmlNode one in pcontents) { string link = one.SelectSingleNode("./td[1]/p[1]/a[@href]").Attributes["href"].Value; link = @"http://ds.fzu.edu.cn/fine/resources/" + link; string filename; filename = one.InnerText.Trim(); if (one.InnerText.Trim() == "二叉树的顺序存储表示") { filename += i; i++; } string swfLink = getSwfName(link); Console.WriteLine("--" + filename + swfLink); DownSwf(swfLink, ptile.InnerText.Trim() + @"/" + filename + ".swf"); Thread.Sleep(1000); } } } } //下载指定的swf static void DownSwf(string url, string desname) { Uri u = new Uri(url); WebClient myWebClient = new WebClient(); myWebClient.DownloadFileAsync(u, desname); } //获取指定页面的那个swf名称 static string getSwfName(string url) { WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(url)); HtmlDocument doc = new HtmlDocument(); doc.Load(ms, Encoding.GetEncoding("gb2312")); HtmlNode hd = doc.DocumentNode; string str = hd.SelectSingleNode("//a[@href]").Attributes["href"].Value; return @"http://ds.fzu.edu.cn/fine/resources/" + str; } } }
写完运行。看着如下这个界面。。这个我只是为了让我看到进度。同时后台也在下载。
运行完成后。文件夹和文件自动命名完成是这样的。。
下载地址:打包动画演示下载
我的博客:http://leaver.me
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库