예제 #1
0
        private static ExGallery GetExGalleryFromHtml(string link, string htmlSource)
        {
            if (htmlSource == null)
            {
                return(null);
            }

            var l = new ExGallery()
            {
                Link = link
            };
            HtmlDocument htmlDocument = new HtmlDocument()
            {
                OptionFixNestedTags = true
            };

            htmlDocument.LoadHtml(htmlSource);
            try
            {
                HtmlNodeCollection imageNodes = htmlDocument.DocumentNode.SelectNodes("//div[@id='gdt']/div[@class!='c']");
                foreach (var node in imageNodes)
                {
                    l.Add(ExGallery.GetImageListItemFromNode(node));
                }
                l.Rating            = ReadRating(htmlDocument);
                l.Title             = ReadTitle(htmlDocument);
                l.JapaneseTitle     = ReadJapaneseTitle(htmlDocument);
                l.PageCount         = ReadPageCount(htmlDocument);
                l.CurrentPageNumber = ReadCurrentPageNumber(htmlDocument);
                l.FileCount         = ReadFileCount(htmlDocument);
                l.Tags        = ReadTags(htmlDocument);
                l.Language    = ReadLanguage(htmlDocument);
                l.IsFavorited = ReadIsFavorited(htmlDocument);
                l.Thumb       = ReadThumb(htmlDocument);

                HtmlNodeCollection commentNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='c1']");
                if (commentNodes != null)
                {
                    foreach (var node in commentNodes)
                    {
                        l.Comments.Add(ExComment.FromNode(node));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(l);
        }
예제 #2
0
        public async Task PostCommentAsync(string comment)
        {
            var requestBody = $"commenttext={WebUtility.UrlEncode(comment)}&postcomment=Post+Comment";



            var httpClient = new Windows.Web.Http.HttpClient(new HttpBaseProtocolFilter());
            var message    = new Windows.Web.Http.HttpRequestMessage(
                new Windows.Web.Http.HttpMethod("POST"),
                new Uri(this.Link))
            {
                Content = new HttpStringContent(requestBody)
            };

            message.Content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded");
            message.Headers["Cookie"]           = await ExClient.GetExCookieAsync("");

            var response = await httpClient.SendRequestAsync(message);

            var responseString = await response.Content.ReadAsStringAsync();


            // Handle error page returned from server
            if (true) // sccuess
            {
                // Refresh the commenet list
                HtmlDocument htmlDocument = new HtmlDocument()
                {
                    OptionFixNestedTags = true
                };
                htmlDocument.LoadHtml(responseString);
                this.Comments.Clear();
                HtmlNodeCollection commentNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='c1']");
                if (commentNodes != null)
                {
                    foreach (var node in commentNodes)
                    {
                        this.Comments.Add(ExComment.FromNode(node));
                    }
                }
            }
        }