예제 #1
0
        public async Task ExecuteBodyCommand()
        {
            if (IsBodyBusy)
            {
                return;
            }

            IsBodyBusy = true;

            try
            {
                BodyPosts.Clear();
                await getBodyArticleData();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessagingCenter.Send(new MessagingCenterAlert
                {
                    Title   = "Error",
                    Message = "Unable to load items.",
                    Cancel  = "OK"
                }, "message");
            }
            finally
            {
                IsBodyBusy = false;
            }
        }
예제 #2
0
        public async Task getBodyArticleData()
        {
            if (BodyPosts.Count != 0)
            {
                return;
            }

            string htmlPage;

            try
            {
                using (var client = new HttpClient())
                {
                    htmlPage = await client.GetStringAsync("http://id.wikihow.com/Halaman-Utama").ConfigureAwait(false);
                }


                htmlDocument.LoadHtml(htmlPage);
                var innerText = htmlDocument.DocumentNode
                                .Descendants("div")
                                .Where(o => o.GetAttributeValue("id", "") == "fa_container").FirstOrDefault();

                innerHtmlDocument.LoadHtml(innerText.OuterHtml);

                var td = innerHtmlDocument.DocumentNode
                         .Descendants("td").ToList();

                PostHelper ph        = new PostHelper();
                var        bodyposts = ph.GetPostFromTd(td);
                BodyPosts.ReplaceRange(bodyposts);
                #region unused
                //foreach (var div in td)
                //{
                //    Post newPosts = new Post();
                //    string imageUrl = "";
                //    string title = "";
                //    string url = "";


                //    imageUrl = Regex.Match(div.OuterHtml, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;
                //    title = div.InnerText;
                //    url = Regex.Match(div.OuterHtml, "<a.+?href=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;

                //    newPosts.Title = title;
                //    newPosts.ImageUrl = imageUrl;
                //    if (!url.Contains("http:")) url = "http:" + url;
                //    newPosts.Url = url;

                //    BodyPosts.Add(newPosts);

                //}
                #endregion
            }
            catch (Exception)
            {
            }
        }