/// <summary> /// 解析当前元素 /// </summary> /// <returns></returns> protected override IResut[] ParseCurrentItems() { var licenceDic = GetLicenceDic(HtmlSource); var resut = new Resut(); foreach (var licence in licenceDic) { resut.Add(licence.Key, licence.Value); } resut.Add("Url", CurrentUrl); return(new IResut[] { resut }); }
/// <summary> /// ParseCurrentItems /// </summary> /// <returns></returns> protected override IResut[] ParseCurrentItems() { var resultList = new List <IResut>(); var html = _httpHelper.GetHtmlByGet(CurrentUrl); var documentNode = HtmlAgilityPack.HtmlAgilityPackHelper.GetDocumentNodeByHtml(html); var htmlNodeCollection = documentNode.SelectNodes("//div[@class='ui-box-body']//li[@class='item']"); if (htmlNodeCollection == null) { return(resultList.ToArray()); } foreach (var htmlNode in htmlNodeCollection) { IResut resut = new Resut(); var productName = HttpUtility.HtmlDecode(htmlNode.SelectSingleNode(".//div[@class='detail']//a")?.InnerText ?? string.Empty); var productUrl = htmlNode.SelectSingleNode(".//div[@class='detail']//a")?.Attributes["href"].Value ?? string.Empty; var productId = Regex.Match(Regex.Match(productUrl, @"\d+_\d+").Value, @"(?<=_)\d+").Value; var price = Regex.Match(htmlNode.SelectSingleNode(".//b")?.InnerText ?? string.Empty, @"\d+\.?\d+").Value; var priceOld = Regex.Match(htmlNode.SelectSingleNode(".//del")?.InnerText ?? string.Empty, @"\d+\.?\d+").Value; var orderNum = Regex.Match(htmlNode.SelectSingleNode(".//div[@class='recent-order']")?.InnerText ?? string.Empty, @"\d+").Value; resut.Add("shopId", _shopId); resut.Add("productName", productName); resut.Add("productUrl", $"https:{productUrl}"); resut.Add("productId", productId); resut.Add("price", FormatNumber(price)); resut.Add("priceOld", FormatNumber(priceOld)); resut.Add("orderNum", FormatNumber(orderNum)); resultList.Add(resut); } return(resultList.ToArray()); }