public string GetShopSummary(string originList) { string detailList = ""; string sumStr = ""; List <string> list = new List <string>(originList.Split(',')); int strCount = 0; int count = list.Count; foreach (string str in list) { try { detailList += T_AccountBLL.GetCompanyName(Convert.ToInt32(str)) + "[" + Convert.ToInt32(str) + "]<br/>"; if (strCount < 5) { sumStr += T_AccountBLL.GetCompanyName(Convert.ToInt32(str)) + ","; } strCount++; } catch (Exception ex) { return("没有找到有关【" + str + "】这个Id相关的信息!"); } } Dictionary <string, string> dic = new Dictionary <string, string>() { { "list", "" }, { "count", "" }, { "strsum", "" }, { "detail", "" } }; dic["list"] = CommonLib.Helper.JsonSerializeObject(list); dic["count"] = count.ToString(); dic["detail"] = detailList; dic["strsum"] = sumStr.Substring(0, sumStr.LastIndexOf(',')); return(CommonLib.Helper.JsonSerializeObject(dic)); }
public static Dictionary <string, string> GetForumContent(string url) { Dictionary <string, string> dic = new Dictionary <string, string>() { { "title", "" }, { "user", "" } }; if (url.IndexOf("www.i200.cn/bbs") < 0) { return(null);//不是合法地址 } //制定编码格式 var encoding = Encoding.GetEncoding("utf-8"); //url的设置 var request = (HttpWebRequest)WebRequest.Create(url); //设置请求的方式 request.Method = "Get"; //设置Content-Type 的值 //request.ContentType = "application/x-www-form-urlencoded"; //request.ContentLength = data.Length; //var outStream = request.GetRequestStream(); //outStream.Write(data, 0, data.Length); //outStream.Close(); var response = (HttpWebResponse)request.GetResponse(); var srContent = new System.IO.StreamReader(response.GetResponseStream(), encoding); //获取抓取下来的页面内容 var strPage = srContent.ReadToEnd(); response.Close(); srContent.Close(); //获取帖子标题 Regex regTitle = new Regex(@"(?i)(?<=<a.*?id=""thread_subject"".*?>)[^<]+(?=</a>)"); MatchCollection mcTitle = regTitle.Matches(strPage); //获取帖子发表时间 Regex regTime = new Regex(@"(?i)(?<=<em.*?id=""authorposton.*?>发表于)[^<]+(?=</em>)"); MatchCollection mcTime = regTime.Matches(strPage); if (mcTime.Count == 0) { regTime = new Regex(@"(?i)(?<=<em.*?id=""authorposton.*?>发表于.*<span.*title="")[^<]+(?="">)"); mcTime = regTime.Matches(strPage); } string postUser = strPage.Substring(strPage.IndexOf("class=\"pi\""), 300); //获取发帖人 Regex regUser = new Regex(@"(?i)(?<=<a.*?uid=)[^<]+(?="".*?target)"); MatchCollection mcUser = regUser.Matches(postUser); if (mcUser.Count == 0) { regUser = new Regex(@"(?i)(?<=匿名.*?<em>)[^<]+(?=</em>)"); mcUser = regUser.Matches(postUser); } Sys_TaskDailyInfo model = new Sys_TaskDailyInfo(); dic["title"] = mcTitle[0].Groups[0].ToString(); if (mcUser[0].Groups[0].ToString().IndexOf('.') >= 0) { dic["user"] = "******"; } else { try { int accountid = T_AccountBLL.GetAccIdBybbsId(Convert.ToInt32(mcUser[0].Groups[0].ToString())); dic["user"] = T_AccountBLL.GetCompanyName(accountid); } catch (Exception ex) { Logger.Error("转换论坛ID出错!", ex); dic["user"] = "******"; } } return(dic); }