/// <summary>
        /// This is used to scrape a single deck by calling the function on the webpage that copies the deck to clipboard
        /// </summary>
        /// <param name="input">The necessary properties to scrape the deck properly</param>
        /// <returns>The text deck that can be imported in MTGA</returns>
        public string GetDeck(DeckScraperDeckInputs input)
        {
            HtmlWeb      hw  = new HtmlWeb();
            HtmlDocument doc = hw.Load(input.UrlDownloadDeck);

            var regexTextDeck = new Regex("innerHTML=\"(.*?)\"");

            var textDeck = regexTextDeck.Match(doc.DocumentNode.InnerHtml).Groups[1].Value.Replace(@"\n", Environment.NewLine);

            return(textDeck);
        }
        public DeckScraperDeckInputs DownloadDeckFromDeckView(string urlViewDeck)
        {
            var doc = LoadMtgGoldfishUrl(urlViewDeck);

            try
            {
                var name = doc.DocumentNode.SelectSingleNode("//h2").InnerText.Split(new[] { "Suggest" }, StringSplitOptions.None)[0].Trim();
                if (name == "Sample Deck" || name == "Description")
                {
                    name = doc.DocumentNode.SelectSingleNode("//h1[@class='deck-view-title']").InnerText
                           .Split(new[] { "Suggest" }, StringSplitOptions.None)[0]
                           .Trim()
                           .Split(new[] { '\n' }, StringSplitOptions.None)[0]
                           .Trim();
                }

                // Get date created
                var str       = doc.DocumentNode.SelectSingleNode("//div[@class='deck-view-description']").InnerText.Trim();
                var regexDate = new Regex(@"20\d\d-\d\d-\d\d", RegexOptions.Multiline);
                var strDate   = regexDate.Match(str).Groups[1].Value;
                if (string.IsNullOrWhiteSpace(strDate))
                {
                    strDate = str.Split('\n').Last().Trim();
                }

                var dateCreated = ParseDateCreated(strDate, name, urlViewDeck);

                var linksContainingArenaDownload = doc.DocumentNode.SelectNodes("//div[@class='deck-view-tools']//a");
                var urlDownloadDeck = SiteUrl + linksContainingArenaDownload
                                      .Single(i => i.Attributes["href"].Value.StartsWith("/deck/arena_download"))
                                      .Attributes["href"].Value;

                var inputDeck = new DeckScraperDeckInputs(name, dateCreated)
                {
                    UrlViewDeck = urlViewDeck, UrlDownloadDeck = urlDownloadDeck
                };
                return(inputDeck);
            }
            catch (Exception ex)
            {
                //System.Diagnostics.Debugger.Break();
                throw;
            }
        }
示例#3
0
 public string GetDeck(DeckScraperDeckInputs input)
 {
     return(GetTextAreaContent(input.UrlDownloadDeck));
 }
示例#4
0
 /// <summary>
 /// This is used to scrape a single deck by calling the function on the webpage that copies the deck to clipboard
 /// </summary>
 /// <param name="input">The necessary properties to scrape the deck properly</param>
 /// <returns>The text deck that can be imported in MTGA</returns>
 public string GetDeck(DeckScraperDeckInputs input)
 {
     return(input.DeckText);
 }