From 3c0c673c6fd9b5d829d52caa01bf05855ba2c428 Mon Sep 17 00:00:00 2001 From: azhuge233 <17763056+azhuge233@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:34:48 +0800 Subject: [PATCH] Modify giveaway XPath and parse logic due to GOG giveaway banner change. --- GOGGiveawayNotifier/Model/String/ParseStrings.cs | 4 +++- GOGGiveawayNotifier/Module/Parser.cs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/GOGGiveawayNotifier/Model/String/ParseStrings.cs b/GOGGiveawayNotifier/Model/String/ParseStrings.cs index 0ccb0c5..f1e3499 100644 --- a/GOGGiveawayNotifier/Model/String/ParseStrings.cs +++ b/GOGGiveawayNotifier/Model/String/ParseStrings.cs @@ -5,7 +5,9 @@ public static class ParseStrings { public static readonly string removeSpecialCharsRegex = @"[^0-9a-zA-Z]+"; #region Xpath - public static readonly string titleLableXpath = ".//a[@giveaway-banner]"; + public static readonly string giveawayDivXPath = ".//div[contains(@id, \'giveaway\')]"; + public static readonly string giveawayALinkXPath = ".//a[contains(@class, \'giveaway__overlay-link\')]"; + //public static readonly string titleLableXpath = ".//a[@giveaway-banner]"; public static readonly string productTileXPath = ".//div[contains(@class, \'grid\')]//product-tile"; public static readonly string productLinkXPath = ".//a[contains(@class, \'product-tile\')]"; public static readonly string productTitleSpanXPath = ".//a[contains(@class, 'product-tile')]//div[contains(@class, \'product-tile__info\')]//div[contains(@class, \'product-tile__title\')]//product-title//span"; diff --git a/GOGGiveawayNotifier/Module/Parser.cs b/GOGGiveawayNotifier/Module/Parser.cs index 5808ec6..37ac347 100644 --- a/GOGGiveawayNotifier/Module/Parser.cs +++ b/GOGGiveawayNotifier/Module/Parser.cs @@ -23,18 +23,26 @@ public Tuple, List> ParseGiveaway(HtmlDocum try { _logger.LogDebug(debugParseGiveaway); - var titleHref = htmlDoc.DocumentNode.SelectSingleNode(ParseStrings.titleLableXpath); + var giveawayDiv = htmlDoc.DocumentNode.SelectSingleNode(ParseStrings.giveawayDivXPath); var resultList = new List(); var notifyList = new List(); - if (titleHref == null) { + if (giveawayDiv == null) { _logger.LogDebug("No giveaway detected"); _logger.LogDebug($"Done: {debugParseGiveaway}"); return new Tuple, List>(resultList, notifyList); } + var giveawayALink = giveawayDiv.SelectSingleNode(ParseStrings.giveawayALinkXPath); + + if (giveawayALink == null) { + _logger.LogDebug("Get giveaway link failed"); + _logger.LogDebug($"Done: {debugParseGiveaway}"); + return new Tuple, List>(resultList, notifyList); + } + var newGiveaway = new GiveawayRecord { - Name = titleHref.Attributes["ng-href"].Value.Split("/game/")[^1].Replace("_", " "), + Name = giveawayALink.Attributes["href"].Value.Split("/game/").Last().Replace("_", " "), Url = ParseStrings.GiveawayUrl }; var textInfo = new CultureInfo("en-US", false).TextInfo;