C#实现的知识搜索工具 - KBCruiser
平时通过搜索引擎去搜答案,总是觉得有些地方用起来不顺手,总结一下有这么几点
于是自己动手写了个知识搜索的客户端小工具,原理就是向不同的官方网站相应的搜索引擎发送请求,分析显示返回结果,同时在浏览器中实现关键字高亮。目前包含的功能主要有以下几点,
安装包和代码下载放在了codeplex上,
https://kbcruiser.codeplex.com/
以下是效果图
实现中几个有趣的地方,
1. 下载网页通过不同网站对应的正则表达式把标题和相应链接抠出来,每个网站对应的表达式都放在一个叫Profiles.xml的配置文件中,例如msdn的
if (triggerHighlight) { IHTMLDocument2 doc2 = wbContent.Document.DomDocument as IHTMLDocument2; string result = doc2.body.outerHTML; string substitution = null; string pattern = null; foreach (string key in keywords) { pattern = string.Format(@"(>[^<]*?)(\b{0}\b)",key); substitution = "$1<span style='background-color: rgb(255, 255, 0);'>$2</span>"; result = Regex.Replace(result, pattern, substitution, RegexOptions.IgnoreCase); } doc2.body.innerHTML = result; triggerHighlight = false; }