public static List <string> GetTireURLs(bool isFull = false) { List <string> tireUrlList = new List <string>(); List <VehicleBrand> vehicles = new List <VehicleBrand>(); using (var vehicleclient = new VehicleClient()) { var response = vehicleclient.GetAllVehicles(); if (response != null && response.Result != null) { vehicles = response.Result.ToList(); } } if (vehicles != null && vehicles.Any()) { WeeklySitemapJob.Logger.Info("有" + vehicles.Count() + "个车型适配轮胎"); foreach (var vehicle in vehicles.Where(q => q != null)) { foreach (var tiresize in hotTiresizes) { var count = BaseDataDAL.GetTireCount(vehicle.VehicleId, tiresize, isFull); int pagecount = count % 20 > 0 ? count / 20 + 1 : count / 20; for (int i = 1; i <= pagecount; i++) { string w = tiresize.Substring(0, tiresize.IndexOf('/')); string a = tiresize.Substring(tiresize.IndexOf('/') + 1, tiresize.IndexOf('R') - tiresize.IndexOf('/') - 1); string r = tiresize.Substring(tiresize.IndexOf('R') + 1); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}.html", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}.html#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o1.html", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o3.html", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o6.html", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o1.html#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o3.html#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("https://item.tuhu.cn/Tires/{0}/au1-a{1}-r{2}-w{3}-v{4}-o6.html#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); } } } } return(tireUrlList); }
public static bool InsertTireURL(bool isFull = false) { List <string> tireUrlList = new List <string>(); List <VehicleBrand> vehicles = new List <VehicleBrand>(); using (var vehicleclient = new VehicleClient()) { var response = vehicleclient.GetAllVehicles(); if (response != null && response.Result != null) { vehicles = response.Result.ToList(); } } if (vehicles != null && vehicles.Any()) { foreach (var vehicle in vehicles.Where(q => q != null)) { foreach (var tiresize in hotTiresizes) { var count = BaseDataDAL.GetTireCount(vehicle.VehicleId, tiresize, isFull); int pagecount = count % 20 > 0 ? count / 20 + 1 : count / 20; for (int i = 1; i <= pagecount; i++) { string w = tiresize.Substring(0, tiresize.IndexOf('/')); string a = tiresize.Substring(tiresize.IndexOf('/') + 1, tiresize.IndexOf('R') - tiresize.IndexOf('/') - 1); string r = tiresize.Substring(tiresize.IndexOf('R') + 1); tireUrlList.Add(string.Format("http://item.tuhu.cn/Tires/{0}/a{1}-r{2}-w{3}-v{4}.html?oe=", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("http://item.tuhu.cn/Tires/{0}/a{1}-r{2}-w{3}-v{4}.html?oe=#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("http://item.tuhu.cn/Tires/{0}/a{1}-r{2}-w{3}-v{4}-o1.html?oe=#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("http://item.tuhu.cn/Tires/{0}/a{1}-r{2}-w{3}-v{4}-o3.html?oe=#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); tireUrlList.Add(string.Format("http://item.tuhu.cn/Tires/{0}/a{1}-r{2}-w{3}-v{4}-o6.html?oe=#Products", i, a, r, w, vehicle.VehicleId.Replace("-", "_"))); } // tireUrlList.Add(string.Format("http://www.tuhu.cn/spages/Battery.aspx?pid={0}&n={1}&pl={2}", vehicle.VehicleID, i, vehicle.PaiLiang)); } } } WeeklySitemapJob.Logger.Info("有" + tireUrlList.Count() + "需要导入库"); return(InsertURLToDB(tireUrlList, "TireList")); }