/// <summary> /// 获取百度关键词出现的密度 /// </summary> /// <param name="keyWord">标题、关键词</param> /// <returns>如:10 (满为100)</returns> public static int GetBaiDuKeywordDensity(string keyWord) { //获取百度源码 string HtmlCode = GetHttpData("http://www.baidu.com/s?wd=" + keyWord); //百度搜索出来的标题列表 List<string> listTitle = new List<string>(); //列表正则匹配规则 string strrex = @"<h3[sS]*?>(?<url>.*?)</h3>"; //进行正则匹配 MatchCollection mc = Regex.Matches(HtmlCode, strrex); foreach (Match m in mc) { string content =HtmlDecodes(Environment.NewLine + m.Groups["url"].Value); content= ReplaceHtml(content); listTitle.Add(RemoveHTML(content)); } //只匹配第一条 for (int i = 0; i < listTitle.Count; i++) { return Convert.ToInt32(Similarity(listTitle[0], keyWord) * 100); } //相似度列表 // List<double> listSimilarity = new List<double>(); //进行相似度计算 //foreach (string strTitle in listTitle) //{ // listSimilarity.Add(Similarity(strTitle, keyWord)); //} //进行密度计算 //int dev = Convert.ToInt32(stdev(listSimilarity) * 100); //if (dev<=0 || dev > 100) //{ // dev = Convert.ToInt32(average(listSimilarity) * 100); //} //return dev ; return 0; }