예제 #1
0
    protected void OnButton1Clicked(object sender, EventArgs e)
    {
        if (!string.IsNullOrWhiteSpace(txtUrl.Text))
        {
            currentUrl = txtUrl.Text;
            string htmlContent = HttpHelper.GetHttpContent(currentUrl);

            Article article = HtmlToArticle.GetArticle(htmlContent);

            if (article != null && !string.IsNullOrWhiteSpace(article.Title))
            {
                txtTitle.Text   = article.Title;
                txtPubDate.Text = article.PubDate.ToString();

                if (!string.IsNullOrWhiteSpace(article.HtmlContent))
                {
                    string htmlText = HtmlFormatter.FormatHtml(article.HtmlContent, currentUrl);
                    txtContent.Buffer.Text = htmlText;
                }
            }
            else
            {
                txtTitle.Text          = "";
                txtPubDate.Text        = "";
                txtContent.Buffer.Text = "";
            }
        }
        else
        {
            //MessageBox.Show("Please input your article url to extract.");
        }
    }
예제 #2
0
        /// <summary>
        /// Get the article and format the html content.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="html"></param>
        /// <returns></returns>
        public static Article GetArticleAndFormatter(string url, string html = null)
        {
            if (string.IsNullOrWhiteSpace(html))
            {
                html = HttpHelper.GetHttpContent(url);
            }

            Article article = HtmlToArticle.GetArticle(html);

            if (article != null && !string.IsNullOrWhiteSpace(article.HtmlContent))
            {
                article.HtmlContent = HtmlFormatter.FormatHtml(article.HtmlContent, url);
            }

            return(article);
        }
예제 #3
0
 /// <summary>
 /// Get the article from html
 /// </summary>
 /// <param name="html"></param>
 /// <returns></returns>
 public static Article GetArticleFromHtml(string html)
 {
     return(HtmlToArticle.GetArticle(html));
 }