async Task <IEnumerable <IDeal> > IScraper.Scrape(CancellationToken token)
        {
            Url       url      = Url.Create("https://www.gog.com");
            IDocument document = await context.OpenAsync(url, token);

            token.ThrowIfCancellationRequested();

            IHtmlAnchorElement giveawayAnchor = document.Body.QuerySelector <IHtmlAnchorElement>(".giveaway-banner");

            if (giveawayAnchor == null)
            {
                logger.Info("No giveaway found");
                return(new List <IDeal>());
            }

            string onclickContent = giveawayAnchor.GetAttribute("onclick");
            Match  match          = Regex.Match(onclickContent, "'.+'");

            if (!match.Success)
            {
                logger.Info("No onclick found");
                return(new List <IDeal>());
            }

            string encodedJson = match.Value.Trim('\'');
            string json        = Regex.Unescape(encodedJson);

            GoodOldGamesData data = JsonConvert.DeserializeObject <GoodOldGamesData>(json);

            return(new List <IDeal>
            {
                new Deal
                {
                    Image = $"https://images-1.gog-statics.com/{data.Logo.Image}.png",
                    Link = $"https://www.gog.com{data.GameUrl}",
                    Title = data.Title,
                    End = DateTimeOffset.FromUnixTimeMilliseconds(data.EndTime).UtcDateTime
                }
            });
        }
Esempio n. 2
0
 public static string ToJson(this GoodOldGamesData self)
 {
     return(JsonConvert.SerializeObject(self, Converter.Settings));
 }