public List <ToyInformation> Run(List <ToysrusScraping.ToyInformation> toysrusToyInformations) { List <ToyInformation> ret = new List <ToyInformation>(); foreach (var toysrusToyInformation in toysrusToyInformations) { try { var toy = GetAmazonUsingScraping(toysrusToyInformation.ToyName); if (toy.asin != null && toysrusToyInformation.Price < toy.price) { ToyInformation toyInformation = new ToyInformation(); toyInformation.Url = toysrusToyInformation.Url; toyInformation.ToyName = toysrusToyInformation.ToyName; toyInformation.Price = toysrusToyInformation.Price; toyInformation.OnlineStock = toysrusToyInformation.OnlineStock; toyInformation.StoreStockCount = toysrusToyInformation.StoreStockCount; toyInformation.StoreLessStockCount = toysrusToyInformation.StoreLessStockCount; toyInformation.ImageUrl = toysrusToyInformation.ImageUrl; toyInformation.Asin = toy.asin; toyInformation.AmazonPrice = toy.price; toyInformation.AmazonImageUrl = toy.imageUrl; ret.Add(toyInformation); Notify($"Amazon:[{toysrusToyInformation.ToyName}]の取得を行いました。", NotifyStatus.Information); } } catch (Exception ex) { Notify($"Amazon:{ex.ToString()}", NotifyStatus.Exception); } } return(ret); }
private ToyInformation GetToy(string url) { ToyInformation ret = new ToyInformation(); ret.Url = url; string html = Utils.GetHtml(url, Delay); var parser = new HtmlParser(); var doc = parser.Parse(html); var productName = doc.GetElementById("DISP_GOODS_NM"); ret.ToyName = ConvertToyName(productName.InnerHtml); var price = doc.GetElementsByClassName("inTax"); if (price.Count() == 0 || (price.First() as AngleSharp.Dom.Html.IHtmlElement).IsHidden) { } else { ret.Price = Convert.ToInt32(price.First().InnerHtml.Substring(0, price.First().InnerHtml.IndexOf("円")).Replace(",", "")); } var image = doc.GetElementById("slideshow-01"); if (image == null || (image as AngleSharp.Dom.Html.IHtmlAnchorElement).IsHidden) { ret.ImageUrl = "不明"; } else { ret.ImageUrl = "https://www.toysrus.co.jp" + (image as AngleSharp.Dom.Html.IHtmlAnchorElement).PathName; } var isLotManegeYes = doc.GetElementById("isLotManegeYes"); if (isLotManegeYes == null || (isLotManegeYes as AngleSharp.Dom.Html.IHtmlSpanElement).IsHidden) { var stock = doc.GetElementById("isStock"); if (stock == null || (stock as AngleSharp.Dom.Html.IHtmlSpanElement).IsHidden) { ret.OnlineStock = "不明"; } else { var stockStatus = stock.Children[0].Children.Where(x => (x as AngleSharp.Dom.Html.IHtmlSpanElement).IsHidden == false); if (stockStatus.Count() == 0) { ret.OnlineStock = "不明"; } else { var f = stockStatus.First().InnerHtml; ret.OnlineStock = f; } } } else { var isLot_a = doc.GetElementById("isLot_a") as AngleSharp.Dom.Html.IHtmlLabelElement; if (!isLot_a.IsHidden) { ret.OnlineStock = "予約受付中"; } var isLot_b = doc.GetElementById("isLot_b") as AngleSharp.Dom.Html.IHtmlLabelElement; if (!isLot_b.IsHidden) { ret.OnlineStock = "予約受付終了間近"; } var isLot_c = doc.GetElementById("isLot_b") as AngleSharp.Dom.Html.IHtmlLabelElement; if (!isLot_c.IsHidden) { ret.OnlineStock = "予約受付終了"; } var isLot_d = doc.GetElementById("isLot_b") as AngleSharp.Dom.Html.IHtmlLabelElement; if (!isLot_d.IsHidden) { ret.OnlineStock = "注文不可"; } } var sku = doc.GetElementsByName("MAIN_SKU"); if (sku == null) { return(ret); } var storeUrl = $"https://www.toysrus.co.jp/disp/CSfGoodsPageRealShop_001.jsp?sku={(sku[0] as AngleSharp.Dom.Html.IHtmlInputElement).Value}&shopCd="; html = Utils.GetHtml(storeUrl, Delay); doc = parser.Parse(html); var source = doc.Source.Text; int existCount = _exist.Matches(source).Count; int lessExistCount = _lessExist.Matches(source).Count; ret.StoreStockCount = existCount; ret.StoreLessStockCount = lessExistCount; return(ret); }