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);
}
亚马逊 过滤价格 备用
最新推荐文章于 2024-08-24 01:56:24 发布