private List<City> GetCitiesFromWeb(string html) { List<City> cities = new List<City>(); TuanGouWebSite meituanWebsite = TuanGouWebsiteHelper.GetTuanGouWebsite("美团"); List<string> labelAs = Utility.Helper.HtmlHelper.ListOuterHtmlMatchXpath(html, "//a[@class='isonline']"); foreach(var a in labelAs) { City city = new City(); city.TuanGouWebsite = meituanWebsite; city.Name = Utility.Helper.HtmlHelper.InnerText(a).Trim(); city.Url = Utility.Helper.HtmlHelper.AttributeMatchXpath(a, "//a", "href"); if(city.Url!=null&&city.Url!="") cities.Add(city); } return cities; }
private List<Cinema> GetCinemas(SubArea subArea,City city) { List<Cinema> cinemas = new List<Cinema>(); string url = subArea.Url; while (url!=null&&url!="") { string html = Utility.Helper.WebHelper.Get(url,null,null,null,GetMeituanCookies("")); List<string> cinemaHtmls = Utility.Helper.HtmlHelper.ListOuterHtmlMatchXpath(html, "//h4[contains(@class,'J-cinema-label')]/a"); foreach (var cinemaHtml in cinemaHtmls) { if (cinemaHtml.Contains("全部") || cinemaHtml.Contains("其它")) continue; cinemas.Add(new Cinema() { City = city, Name = Utility.Helper.HtmlHelper.InnerText(cinemaHtml), SubAreaName = subArea.Name, Url = Utility.Helper.HtmlHelper.AttributeMatchXpath(cinemaHtml, "//a", "href") }); } url = GetNextPageUrl(html, city.Url); } return cinemas; }
internal static void UpdateCityStatus(City city) { string sql = string.Format("update city set status=1 where id={0}", city.Id); using(MySqlConnection conn = GetDBConnection()) { conn.Execute(sql); } }
internal static void SaveCity(City city) { string sql = "insert ignore into city (website_id,name,url) values(?website_id,?name,?url)"; using (MySqlConnection conn = GetDBConnection()) { conn.Execute(sql, new object[] { new { website_id=city.TuanGouWebsite.Id, name=city.Name, url=city.Url } }); } }
internal static bool IsCityExisted(City city) { string sql = string.Format("select id from city where website_id={0} and name='{1}'", city.TuanGouWebsite.Id, city.Name); using(MySqlConnection conn = GetDBConnection()) { try { var ids = conn.Query(sql); if (ids.Count() > 0) return true; else return false; }catch(Exception ex) { } } return false; }
internal static void UpdateCityStatus(City city) { DBHelper.UpdateCityStatus(city); }