Ejemplo n.º 1
0
        public static void ExecuteSingleArticleScrape(MainPage mainpage, SynchronizationContext theContext, OverviewResult search)
        {
            theContext.Post((_) =>
            {
                mainpage.Pivot.SelectedIndex = 1;
                mainpage.PageDataContext.ArticleLoading = true;
                mainpage.PageDataContext.Articles.Clear();
            }, null);

            ArticleExecute execute = new ArticleExecute();
            execute.Parameters.Url = search.Url;
            execute.Parameters.Type = mainpage.PageDataContext.CurrentArticleGallery;
            execute.Execute();
            var article = execute.Result;

            theContext.Post((_) =>
            {
                mainpage.PageDataContext.InitializeNewArticle(article);
            }, null);
        }
        public OverviewResult ConvertSingleResult(HtmlNode node)
        {
            var aDiv = node.Descendants("div").FirstOrDefault(c => c.Attributes["class"]?.Value == "post-cover-container")?.Descendants("a")?.FirstOrDefault();

            var o = new OverviewResult()
            {
                Title = (node.Descendants("h2").FirstOrDefault()?.Descendants("a")?.FirstOrDefault()?.InnerText ?? "Title not found").Trim(),
                SubTitle = node.Descendants("p")?.FirstOrDefault(c => c.Attributes["class"]?.Value == "description")?.InnerText ?? "Sub title not found",
                ImageUrl = aDiv?.Descendants("img")?.FirstOrDefault()?.Attributes["src"]?.Value ?? string.Empty,
                Url = aDiv?.Attributes["href"]?.Value ?? string.Empty
            };

            //Uri temp;
            //if(Uri.TryCreate(aDiv?.Attributes["href"]?.Value ?? string.Empty, UriKind.Absolute, out temp))
            //    o.Url = temp;
            //else
            //    o.Url = new Uri("");
            o.Title = System.Net.WebUtility.HtmlDecode(o.Title);
            o.SubTitle = System.Net.WebUtility.HtmlDecode(o.SubTitle);
            return o;
        }