Exemple #1
0
        private Comic GetComic(string url, DateTime comicDate)
        {
            var documentUrl = $"{url}/{comicDate.Year}/{comicDate.Month.ToString("00")}/{comicDate.Day.ToString("00")}";

            HtmlDocument    hdoc = new HtmlDocument();
            CookieWebClient wc   = new CookieWebClient();

            Stream read = null;

            try
            {
                read = wc.OpenRead(documentUrl);
            }
            catch (ArgumentException)
            {
                read = wc.OpenRead(Uri.EscapeUriString(documentUrl));
            }
            catch (HtmlWebException)
            {
                wc   = new CookieWebClient();
                read = wc.OpenRead(documentUrl);
            }


            hdoc.Load(read, true);
            var pictureContainer = hdoc.DocumentNode.Descendants("picture")
                                   .FirstOrDefault(d => d.Attributes.Contains("class") &&
                                                   d.Attributes["class"].Value.Contains("item-comic-image"));

            if (pictureContainer == null)
            {
                return(null);
            }

            var imageUrl = pictureContainer.SelectNodes(".//img")
                           .FirstOrDefault()
                           .Attributes["src"]
                           .Value;

            var comic = new Comic
            {
                ImageUrl    = imageUrl,
                PublishDate = comicDate
            };

            return(comic);
        }