internal void GetInfo(Area one_area) { for (int page= 1;page <= 100;page++) { string url = string.Format("http://www.property.hk/unlucky/{0}/{1}/0/",page,one_area.Value); { HttpWebRequest requestScore = (HttpWebRequest)WebRequest.Create(url); string html = Awol.WebHelper.GetResponseStr(requestScore,"utf-8",null,null); if (html != null && html.Length > 100) { MatchCollection matches = Regex.Matches(html, "<TR bgColor.*?</TR>",RegexOptions.Singleline); if (matches.Count < 3) { break; } foreach (Match mac in matches) { MatchCollection details = Regex.Matches(mac.ToString(), "<TD.*?>(.*?)</TD>", RegexOptions.Singleline); if (details.Count < 3) { continue; } string date = details[0].Groups[1].ToString().Trim(); string place = details[1].Groups[1].ToString().Trim(); string level = details[2].Groups[1].ToString().Trim(); string reason = details[3].Groups[1].ToString().Trim(); string detail_url = details[4].ToString().Trim(); detail_url = HandleUrl(detail_url, url); string only_code = Regex.Match(detail_url, "www.property.hk/unlucky_detail/.*?/(.*?.html)", RegexOptions.Singleline).Groups[1].ToString(); ; if (level.Length == 0) level = "-1"; News news = new News(); news.Date = GetDate(date); news.Place = place; news.Level = level; news.Reason = reason; news.Detail_Url = detail_url; news.Only = only_code; news.Area_Id = one_area.Id; MysqlHelper mysqlhelper = new MysqlHelper(); mysqlhelper.InertNews(news); } } } } }
internal List<Area> GetList() { List<Area> list_return = new List<Area>(); string sql = string.Format("select * from area"); DataSet testDataSet = null; MySqlConnection conn = new MySqlConnection(connStr); try { conn.Open(); // 创建一个适配器 MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn); // 创建DataSet,用于存储数据. testDataSet = new DataSet(); // 执行查询,并将数据导入DataSet. adapter.Fill(testDataSet, "result_data"); } // 关闭数据库连接. catch (Exception e) { //log4net.ILog log = log4net.LogManager.GetLogger("MyLogger"); //log.Debug(e.Message); Console.WriteLine(e.Message); //Console.ReadLine(); } finally { conn.Close(); } if (testDataSet != null && testDataSet.Tables["result_data"] != null && testDataSet.Tables["result_data"].Rows != null) { foreach (DataRow testRow in testDataSet.Tables["result_data"].Rows) { string id = testRow["id"].ToString(); string value = testRow["value"].ToString(); string name = testRow["name"].ToString(); Area area = new Area(); area.Value = value; area.Name = name; area.Id = id; list_return.Add(area); } } return list_return; }