Exemple #1
0
 private void AddGridItem(BjsItem item)
 {
     var row = new DataGridViewRow();
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = item.Title });
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = item.ItemNumber });
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = string.Format("${0}",item.Price) });
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = item.Description });
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = item.EstimatedDelivery });
     row.Cells.Add(new DataGridViewTextBoxCell() { Value = item.Category });
     dataGridViewItems.Rows.Add(row);
 }
Exemple #2
0
        private BjsItem ParseItem(string url)
        {
            var itemUrl = string.Format("{0}{1}", RootUrl, url);
            var pageContent = _httpProvider.DownloadContent(itemUrl);
            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(pageContent);
            var item = new BjsItem();
            try
            {
                var titleNode = document.DocumentNode.SelectSingleNode("//h1[contains(@id,'itemNameID')]");
                if (titleNode != null)
                    item.Title = titleNode.InnerText.Trim();
                var itemNumberNode = document.DocumentNode.SelectSingleNode("//p[contains(@id,'productModel')]");
                if (itemNumberNode != null)
                {
                    var itemNumberParts = itemNumberNode.InnerText.Trim().Split('|');
                    if (itemNumberParts.Length > 1)
                    {
                        item.ItemNumber = itemNumberParts[0].Replace("Item:", "").Trim();
                    }
                }
                var priceNode = document.DocumentNode.SelectSingleNode("//input[contains(@name,'addToCartPrice')]");
                if (priceNode != null)
                {
                    double price;
                    var priceStr = priceNode.Attributes["value"].Value;
                    double.TryParse(priceStr, NumberStyles.Any, CultureInfo.InvariantCulture, out price);
                    item.Price = price;
                }
                var descriptionNode = document.DocumentNode.SelectSingleNode("//p[contains(@itemprop,'description')]");
                if (descriptionNode != null)
                {
                    item.Description = Regex.Replace(descriptionNode.InnerText, @"\t|\n|\r", "");
                }
                var estimatedNode = document.DocumentNode.SelectSingleNode("//div[contains(@id,'estimatedDelivery')]");
                if (estimatedNode != null)
                {
                    item.EstimatedDelivery = estimatedNode.InnerText.Replace("Estimated Delivery: ", "");
                    item.EstimatedDelivery = Regex.Replace(item.EstimatedDelivery, @"\t|\n|\r", "");
                    item.EstimatedDelivery = item.EstimatedDelivery.Replace(" <!-- <td> --><!-- </td> -->", "");
                }

                var categoryNode = document.DocumentNode.SelectSingleNode("//li[contains(@id,'pagepath')]");
                if (categoryNode != null)
                {
                    item.Category = categoryNode.InnerText;
                    item.Category = Regex.Replace(item.Category, @"\t|\n|\r", "");
                    item.Category = item.Category.Replace("&gt; ", ">");
                    item.Category = item.Category.Replace("&amp;", "&");
                    item.Category = item.Category.Replace("&#034;", "'");
                }
            }
            catch
            {

            }
            return item;
        }