亚马逊 过滤价格 备用

来源:互联网 发布:淘宝查询历史价格 编辑:程序博客网 时间:2024/04/27 22:28
private void CheckHtmlContent(string pageContent, Product product)        {            #region 秒杀            string pattern = "<[a-zA-Z0-9][^>]+?id=\"priceblock_dealprice\"[^>]+?>(.|\\s)*?</td>";            var matchPrice = Regex.Match(pageContent, pattern);            var salepattern = "<[a-zA-Z0-9][^>]+?id=\"priceblock_saleprice\"[^>]+?>.*?</span>";            var salematchPrice = Regex.Match(pageContent, salepattern);            if (matchPrice.Success)            {                pattern = "<span[^>]*>((?!</span>).*)</span>"; ;                var dealPrice = Regex.Match(matchPrice.Value, pattern);                if (dealPrice.Success)                {                    var truePrice = float.Parse(dealPrice.Groups[1].Value.Substring(product.lang.Length).Replace(",", ""));                    if (truePrice < product.expectPrice)                    {                        if (!product.isAlreadyNotificationExpectPrice)                        {                            product.isAlreadyNotificationExpectPrice = product.isNotificationExpectPrice = true;                        }                    }                    if (truePrice < product.minPrice)                    {                        product.isNotification = true;                        product.minPrice = truePrice;                    }                }                else                    throw new Exception("没有找到秒杀价格_" + product.productID + "\n" + product.url + pageContent);            }            #endregion            #region 特价            //<span id="priceblock_saleprice" class="a-size-medium a-color-price">¥4,599.00</span>            else if (salematchPrice.Success)            {                salepattern = "<span[^>]*>((?!</span>).*)</span>"; ;                var dealPrice = Regex.Match(salematchPrice.Value, salepattern);                if (dealPrice.Success)                {                    var truePrice = float.Parse(dealPrice.Groups[1].Value.Substring(product.lang.Length).Replace(",", ""));                    if (truePrice < product.expectPrice)                    {                        if (!product.isAlreadyNotificationExpectPrice)                        {                            product.isAlreadyNotificationExpectPrice = product.isNotificationExpectPrice = true;                        }                    }                    if (truePrice < product.minPrice)                    {                        product.isNotification = true;                        product.minPrice = truePrice;                    }                }                else                    throw new Exception("没有找到特价价格_" + product.productID + "\n" + product.url + pageContent);            }            #endregion            #region normal            else            {                pattern = "<[a-zA-Z0-9][^>]+?id=\"priceblock_ourprice\"[^>]+?>.*?</span>";                matchPrice = Regex.Match(pageContent, pattern);                if (!matchPrice.Success)                    throw new Exception("没有找到平时价格_" + product.productID + "\n" + product.url + pageContent);                else                {                    //pattern = "(¥)(\\d+)(,\\d+)*";                    pattern = "<span[^>]*>((?!</span>).*)</span>";                    var dealPrice = Regex.Match(matchPrice.Value, pattern);                    if (dealPrice.Success)                    {                        var truePrice = float.Parse(dealPrice.Groups[1].Value.Substring(product.lang.Length).Replace(",", ""));                        if (truePrice < product.expectPrice)                        {                            if (!product.isAlreadyNotificationExpectPrice)                            {                                product.isAlreadyNotificationExpectPrice = product.isNotificationExpectPrice = true;                            }                        }                        if (truePrice < product.minPrice)                        {                            product.isNotification = true;                            product.minPrice = truePrice;                        }                    }                    else                        throw new Exception("没有找到平时价格_" + product.productID + "\n" + product.url + pageContent);                }            }            #endregion            SendNotification(product);        }

0 0