Beispiel #1
0
        /// <summary>
        /// 获取博客园新闻信息
        /// 返回 -1 表示失败
        /// </summary>
        /// <param name="strNewsTitleList"></param>
        /// <param name="strNewsUrlList"></param>
        /// <param name="strNewsDescList"></param>
        /// <param name="strNewsAuthorList"></param>
        /// <param name="strNewsDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetNewsFromCnBlogs(ref List <String> strNewsTitleList, ref List <String> strNewsUrlList, ref List <String> strNewsDescList, ref List <String> strNewsAuthorList, ref List <String> strNewsDateTimeList)
        {
            strNewsTitleList.Clear();
            strNewsUrlList.Clear();
            strNewsDescList.Clear();
            strNewsAuthorList.Clear();
            strNewsDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;
                for (int i = 0; i < ConfigEntity.CnBlogs_News.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.CnBlogs_News[i], Encoding.UTF8, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(strHTML);

                        HtmlNode           parentNode   = doc.GetElementbyId("news_list");
                        HtmlNodeCollection titleList    = parentNode.SelectNodes("//div[2]/h2[@class='news_entry']/a");
                        HtmlNodeCollection descList     = parentNode.SelectNodes("//div[2]/div[1][@class='entry_summary']");
                        HtmlNodeCollection authorList   = parentNode.SelectNodes("//div[2]/div[2][@class='entry_footer']/a[@class='gray']");
                        HtmlNodeCollection dateTimeList = parentNode.SelectNodes("//div[2]/div[2][@class='entry_footer']/span[@class='gray']");

                        if (titleList != null && descList != null && authorList != null && dateTimeList != null)
                        {
                            if (titleList.Count == descList.Count && descList.Count == authorList.Count && authorList.Count == dateTimeList.Count)
                            {
                                for (int j = 0; j < titleList.Count; j++)
                                {
                                    nCount++;

                                    strNewsTitleList.Add(titleList[j].InnerText.Trim());
                                    strNewsUrlList.Add("http://news.cnblogs.com" + titleList[j].Attributes["href"].Value.ToString().Trim());
                                    strNewsDescList.Add(descList[j].InnerText.Trim());
                                    strNewsAuthorList.Add(authorList[j].InnerHtml.Trim());
                                    strNewsDateTimeList.Add(dateTimeList[j].InnerText.Trim());
                                }
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strNewsTitleList.Clear();
                strNewsUrlList.Clear();
                strNewsDescList.Clear();
                strNewsAuthorList.Clear();
                strNewsDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetNewsFromCnBlogs,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取博客园首页文章信息
        /// 返回 -1 表示失败
        /// </summary>
        /// <param name="strHomePageTitleList"></param>
        /// <param name="strHomePageUrlList"></param>
        /// <param name="strHomePageDescList"></param>
        /// <param name="strHomePageAuthorList"></param>
        /// <param name="strHomePageDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetHomePageBlogsFromCnBlogs(ref List <String> strHomePageTitleList, ref List <String> strHomePageUrlList, ref List <String> strHomePageDescList, ref List <String> strHomePageAuthorList, ref List <String> strHomePageDateTimeList)
        {
            strHomePageTitleList.Clear();
            strHomePageUrlList.Clear();
            strHomePageDescList.Clear();
            strHomePageAuthorList.Clear();
            strHomePageDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;

                for (int i = 0; i < ConfigEntity.CnBlogs_HomePage.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.CnBlogs_HomePage[i], Encoding.UTF8, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(strHTML);

                        HtmlNode           parentNode = doc.GetElementbyId("post_list");
                        HtmlNodeCollection titleList  = parentNode.SelectNodes("//div[2]/h3/a[@class='titlelnk']");
                        HtmlNodeCollection descList   = parentNode.SelectNodes("//div[2]/p[@class='post_item_summary']");
                        HtmlNodeCollection footerList = parentNode.SelectNodes("//div[2]/div[1]/a[@class='lightblue']");

                        if (titleList != null && descList != null && footerList != null)
                        {
                            if (titleList.Count == descList.Count && descList.Count == footerList.Count)
                            {
                                for (int j = 0; j < titleList.Count; j++)
                                {
                                    nCount++;

                                    strHomePageTitleList.Add(titleList[j].InnerText.Trim());
                                    strHomePageUrlList.Add(titleList[j].Attributes["href"].Value.ToString().Trim());
                                    strHomePageDescList.Add(descList[j].InnerText.Trim());
                                    strHomePageAuthorList.Add(footerList[j].InnerHtml.Trim());
                                    strHomePageDateTimeList.Add(footerList[j].NextSibling.InnerText.Replace("发布于", "").Trim());
                                }
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strHomePageTitleList.Clear();
                strHomePageUrlList.Clear();
                strHomePageDescList.Clear();
                strHomePageAuthorList.Clear();
                strHomePageDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetHomePageBlogsFromCnBlogs,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 从 CIOAge 网页上获取到文章信息
        /// </summary>
        /// <param name="strCIOAgeHomePageTitleList"></param>
        /// <param name="strCIOAgeHomePageUrlList"></param>
        /// <param name="strCIOAgeHomePageDescList"></param>
        /// <param name="strCIOAgeHomePageAuthorList"></param>
        /// <param name="strCIOAgeHomePageDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetHomePageBlogsFromCIOAge(ref List <String> strCIOAgeHomePageTitleList, ref List <String> strCIOAgeHomePageUrlList, ref List <String> strCIOAgeHomePageDescList, ref List <String> strCIOAgeHomePageAuthorList, ref List <String> strCIOAgeHomePageDateTimeList)
        {
            strCIOAgeHomePageTitleList.Clear();
            strCIOAgeHomePageUrlList.Clear();
            strCIOAgeHomePageDescList.Clear();
            strCIOAgeHomePageAuthorList.Clear();
            strCIOAgeHomePageDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;
                for (int i = 0; i < ConfigEntity.CIOAge_HomePage.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.CIOAge_HomePage[i], Encoding.Default, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(strHTML);

                        HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//a[@target='_blank']");
                        if (nodes.Count <= 0)
                        {
                            return(-1);
                        }

                        for (int j = 0; j < nodes.Count; j++)
                        {
                            HtmlAttribute attribute = nodes[j].Attributes["href"];
                            if (attribute != null)
                            {
                                String strAttributeValue = attribute.Value;
                                for (int z = 0; z < ConfigEntity.CIOAge_HomePage_Filter.Length; z++)
                                {
                                    if (strAttributeValue.Contains(ConfigEntity.CIOAge_HomePage_Filter[z]) == true)
                                    {
                                        if (String.IsNullOrEmpty(nodes[j].InnerText) == false && nodes[j].InnerText.Length >= 4)
                                        {
                                            nCount++;

                                            strCIOAgeHomePageTitleList.Add(nodes[j].InnerText);
                                            strCIOAgeHomePageUrlList.Add(strAttributeValue);
                                            strCIOAgeHomePageDescList.Add(nodes[j].InnerText);
                                            strCIOAgeHomePageAuthorList.Add("CIOAge.com");
                                            strCIOAgeHomePageDateTimeList.Add(strAttributeValue.Substring(strAttributeValue.IndexOf("/art/") + 5, 6).Insert(4, "-"));

                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strCIOAgeHomePageTitleList.Clear();
                strCIOAgeHomePageUrlList.Clear();
                strCIOAgeHomePageDescList.Clear();
                strCIOAgeHomePageAuthorList.Clear();
                strCIOAgeHomePageDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetHomePageBlogsFromCIOAge,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取资安人文章列表前 5 页的所有文章
        /// </summary>
        /// <param name="strInfoSecurityTitleList"></param>
        /// <param name="strInfoSecurityUrlList"></param>
        /// <param name="strInfoSecurityDescList"></param>
        /// <param name="strInfoSecurityAuthorList"></param>
        /// <param name="strInfoSecurityDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetArticlesFromInfoSecurity(ref List <String> strInfoSecurityTitleList, ref List <String> strInfoSecurityUrlList, ref List <String> strInfoSecurityDescList, ref List <String> strInfoSecurityAuthorList, ref List <String> strInfoSecurityDateTimeList)
        {
            strInfoSecurityTitleList.Clear();
            strInfoSecurityUrlList.Clear();
            strInfoSecurityDescList.Clear();
            strInfoSecurityAuthorList.Clear();
            strInfoSecurityDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;
                for (int i = 0; i < ConfigEntity.InfoSecurity_Article.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.InfoSecurity_Article[i], Encoding.UTF8, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(strHTML);

                        HtmlNodeCollection titleNodes = htmlDoc.DocumentNode.SelectNodes("//a[@class='link_title_blue01']");
                        if (titleNodes == null || titleNodes.Count <= 0)
                        {
                            return(-1);
                        }

                        for (int j = 0; j < titleNodes.Count; j++)
                        {
                            HtmlNode parentNode = titleNodes[j].ParentNode;
                            if (parentNode != null && parentNode.Name == "td")
                            {
                                if (parentNode.InnerHtml.Contains("<span class=\"content_gray02\">") == true)
                                {
                                    HtmlNode           titleNode    = null;
                                    HtmlNode           dateTimeNode = null;
                                    HtmlNodeCollection childNodes   = parentNode.ChildNodes;

                                    if (childNodes != null && childNodes.Count > 0)
                                    {
                                        foreach (HtmlNode node in childNodes)
                                        {
                                            if (node.Name == "a")
                                            {
                                                HtmlAttribute titleHref      = node.Attributes["href"];
                                                HtmlAttribute titleNodeClass = node.Attributes["class"];
                                                if (titleNodeClass != null && titleHref != null)
                                                {
                                                    if (titleNodeClass.Value == "link_title_blue01")
                                                    {
                                                        titleNode = node;
                                                    }
                                                }
                                            }

                                            if (node.Name == "span")
                                            {
                                                HtmlAttribute dateTimeNodeClass = node.Attributes["class"];
                                                if (dateTimeNodeClass != null)
                                                {
                                                    if (dateTimeNodeClass.Value == "content_gray02")
                                                    {
                                                        dateTimeNode = node;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (titleNode != null && dateTimeNode != null)
                                    {
                                        try
                                        {
                                            HtmlAttribute titleNodeHref = titleNode.Attributes["href"];
                                            if (titleNodeHref != null)
                                            {
                                                String strTitle    = titleNode.InnerText.Trim();
                                                String strUrl      = "http://www.informationsecurity.com.tw" + titleNodeHref.Value.Trim().Substring(2);
                                                String strDateTime = Convert.ToDateTime(dateTimeNode.InnerText.Trim()).ToString("yyyy-MM-dd HH:mm");

                                                strInfoSecurityTitleList.Add(strTitle);
                                                strInfoSecurityUrlList.Add(strUrl);
                                                strInfoSecurityDescList.Add(strTitle);
                                                strInfoSecurityAuthorList.Add("资安人");
                                                strInfoSecurityDateTimeList.Add(strDateTime);

                                                nCount++;
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strInfoSecurityTitleList.Clear();
                strInfoSecurityUrlList.Clear();
                strInfoSecurityDescList.Clear();
                strInfoSecurityAuthorList.Clear();
                strInfoSecurityDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetBlogsFromInfoSecurity,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 获取 C++ 博客首页文章信息
        /// 返回 -1 表示失败
        /// </summary>
        /// <param name="strBlogTitleList"></param>
        /// <param name="strBlogUrlList"></param>
        /// <param name="strBlogDescList"></param>
        /// <param name="strBlogAuthorList"></param>
        /// <param name="strBlogDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetHomePageBlogsFromCppBlog(ref List <String> strBlogTitleList, ref List <String> strBlogUrlList, ref List <String> strBlogDescList, ref List <String> strBlogAuthorList, ref List <String> strBlogDateTimeList)
        {
            strBlogTitleList.Clear();
            strBlogUrlList.Clear();
            strBlogDescList.Clear();
            strBlogAuthorList.Clear();
            strBlogDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;
                for (int i = 0; i < ConfigEntity.CppBlog_HomePage.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.CppBlog_HomePage[i], Encoding.UTF8, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(strHTML);

                        HtmlNodeCollection parentNodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='post']");
                        if (parentNodes.Count <= 0)
                        {
                            return(-1);
                        }
                        HtmlNode           parentNode = parentNodes[0];
                        HtmlNodeCollection titleList  = parentNode.SelectNodes("//h3");
                        HtmlNodeCollection descList   = parentNode.SelectNodes("//h4");
                        HtmlNodeCollection footerList = parentNode.SelectNodes("//p[@class='postfoot']");
                        HtmlNodeCollection authorList = parentNode.SelectNodes("//a[@class='clsSubText']");

                        if (titleList != null && descList != null && footerList != null)
                        {
                            if (titleList.Count == descList.Count && descList.Count == footerList.Count)
                            {
                                for (int j = 0; j < titleList.Count; j++)
                                {
                                    nCount++;

                                    strBlogTitleList.Add(titleList[j].InnerText.Trim());
                                    strBlogUrlList.Add(titleList[j].FirstChild.Attributes["href"].Value.ToString().Trim());
                                    strBlogDescList.Add(descList[j].InnerText.Trim());
                                    strBlogAuthorList.Add(authorList[j].InnerHtml.Trim());
                                    strBlogDateTimeList.Add(authorList[j].PreviousSibling.InnerText.Substring(0, 16).Trim());
                                }
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strBlogTitleList.Clear();
                strBlogUrlList.Clear();
                strBlogDescList.Clear();
                strBlogAuthorList.Clear();
                strBlogDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetHomePageBlogsFromCppBlog,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 发布用户选择的按钮单击事件处理
        /// </summary>
        private String btnPublishSelectedClick()
        {
            String strResult = String.Empty;

            String strSelected = cbBoxDefaultURL.SelectedItem.ToString();

            if (String.IsNullOrEmpty(strSelected) == false)
            {
                String strCategories = GetSelectedCategories();
                switch (strSelected)
                {
                case ConfigEntity.TechCrunch_Article_Name:
                {
                    /* TechCrunch 文章列表 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strTechCrunchHTML = String.Empty;
                        String strTechCrunchURL  = strTechCrunchUrlList[nIndex];
                        if (DownloadBLL.DownloadHTML2String(strTechCrunchURL, Encoding.UTF8, ref strTechCrunchHTML) == true && String.IsNullOrEmpty(strTechCrunchHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            TechCrunchBLL.GetArticleBodyFromTechCrunch(strTechCrunchHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.title       = strTechCrunchTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.post_status = "new";
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                case ConfigEntity.InfoSecurity_Article_Name:
                {
                    /* 资安人文章列表 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strInfoSecurityHTML = String.Empty;
                        String strInfoSecurityURL  = strInfoSecurityUrlList[nIndex];
                        if (DownloadBLL.DownloadHTML2String(strInfoSecurityURL, Encoding.UTF8, ref strInfoSecurityHTML) == true && String.IsNullOrEmpty(strInfoSecurityHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            InfoSecurityBLL.GetArticleBodyFromInfoSecurity(strInfoSecurityHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.title       = strInfoSecurityTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.post_status = "new";
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                case ConfigEntity.CIOAge_HomePage_Name:
                {
                    /* CIOAge 首页 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strCIOAgeBlogsHTML = String.Empty;
                        String strCIOAgeBlogsURL  = strCIOAgeHomePageUrlList[nIndex];
                        if (DownloadBLL.DownloadHTML2String(strCIOAgeBlogsURL, Encoding.Default, ref strCIOAgeBlogsHTML) == true && String.IsNullOrEmpty(strCIOAgeBlogsHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            CIOAgeBLL.GetArticleBodyFromCIOAge(strCIOAgeBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.title       = strCIOAgeHomePageTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.post_status = "new";
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                case ConfigEntity.CppBlog_HomePage_Name:
                {
                    /* C++ 博客首页区 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strCppBlogBlogsHTML = String.Empty;
                        String strCppBlogBlogsURL  = strCppBlogHomePageUrlList[nIndex];
                        if (DownloadBLL.DownloadHTML2String(strCppBlogBlogsURL, Encoding.UTF8, ref strCppBlogBlogsHTML) == true && String.IsNullOrEmpty(strCppBlogBlogsHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            CppBlogBLL.GetBlogsBodyFromCppBlog(strCppBlogBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.dateCreated = DateTime.Now;
                                post.title       = strCppBlogHomePageTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }

                    break;
                }

                case ConfigEntity.CnBlogs_HomePage_Name:
                {
                    /* 博客园首页区 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strCnBlogsBlogsHTML = String.Empty;
                        String strCnBlogsBlogsURL  = strCnBlogsHomePageUrlList[nIndex];
                        if (DownloadBLL.DownloadHTML2String(strCnBlogsBlogsURL, Encoding.UTF8, ref strCnBlogsBlogsHTML) == true && String.IsNullOrEmpty(strCnBlogsBlogsHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            CnBlogsBLL.GetBlogsBodyFromCnBlogs(strCnBlogsBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.dateCreated = DateTime.Now;
                                post.title       = strCnBlogsHomePageTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                case ConfigEntity.CnBlogs_News_Name:
                {
                    /* 博客园新闻区 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strCnBlogsNewsHTML = String.Empty;
                        String strCnBlogsNewsURL  = strCnBlogsNewsUrlList[nIndex];;
                        if (DownloadBLL.DownloadHTML2String(strCnBlogsNewsURL, Encoding.UTF8, ref strCnBlogsNewsHTML) == true && String.IsNullOrEmpty(strCnBlogsNewsHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            CnBlogsBLL.GetNewsBodyFromCnBlogs(strCnBlogsNewsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.dateCreated = DateTime.Now;
                                post.title       = strCnBlogsNewsTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                case ConfigEntity.CnBlogs_Precious_Name:
                {
                    /* 博客园精华区 */
                    for (int i = 0; i < dgvDefault.SelectedRows.Count; i++)
                    {
                        Int32 nIndex = (Int32)dgvDefault.SelectedRows[i].Cells[0].Value - 1;

                        String strCnBlogsBlogsHTML = String.Empty;
                        String strCnBlogsBlogsURL  = strCnBlogsPreciousUrlList[nIndex];;
                        if (DownloadBLL.DownloadHTML2String(strCnBlogsBlogsURL, Encoding.UTF8, ref strCnBlogsBlogsHTML) == true && String.IsNullOrEmpty(strCnBlogsBlogsHTML) == false)
                        {
                            String strBodyOuterHtml = String.Empty;
                            String strBodyInnerHtml = String.Empty;
                            String strBodyInnerText = String.Empty;

                            CnBlogsBLL.GetBlogsBodyFromCnBlogs(strCnBlogsBlogsHTML, ref strBodyOuterHtml, ref strBodyInnerHtml, ref strBodyInnerText);

                            try
                            {
                                MetaWeblogEntity.Post post = new MetaWeblogEntity.Post();
                                post.dateCreated = DateTime.Now;
                                post.title       = strCnBlogsPreciousTitleList[nIndex];
                                post.description = strBodyOuterHtml;
                                post.categories  = String.IsNullOrEmpty(strCategories) == true ? null : strCategories.Split(',');
                                post.dateCreated = DateTime.Now;
                                String strPostID = metaWeblog.newPost(String.Empty, strUserName, strPassword, post, true);

                                strResult = "   Publish Blog Succeed.";
                            }
                            catch (Exception ex)
                            {
                                strResult = "   Publish Blog Failed,Error Message: " + ex.Message;
                            }
                        }
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }

                ClearDefaultSelectedBlogs();
            }

            System.Threading.Thread.Sleep(1500);

            return(strResult);
        }
Beispiel #7
0
        /// <summary>
        /// 获取 TechCrunch 文章列表
        /// </summary>
        /// <param name="strTechCrunchTitleList"></param>
        /// <param name="strTechCrunchUrlList"></param>
        /// <param name="strTechCrunchDescList"></param>
        /// <param name="strTechCrunchAuthorList"></param>
        /// <param name="strTechCrunchDateTimeList"></param>
        /// <returns></returns>
        public static Int32 GetArticlesFromTechCrunch(ref List <String> strTechCrunchTitleList, ref List <String> strTechCrunchUrlList, ref List <String> strTechCrunchDescList, ref List <String> strTechCrunchAuthorList, ref List <String> strTechCrunchDateTimeList)
        {
            strTechCrunchTitleList.Clear();
            strTechCrunchUrlList.Clear();
            strTechCrunchDescList.Clear();
            strTechCrunchAuthorList.Clear();
            strTechCrunchDateTimeList.Clear();

            try
            {
                Int32 nCount = -1;
                for (int i = 0; i < ConfigEntity.TechCrunch_Article.Length; i++)
                {
                    String strHTML = String.Empty;
                    if (DownloadBLL.DownloadHTML2String(ConfigEntity.TechCrunch_Article[i], Encoding.Default, ref strHTML) == true && String.IsNullOrEmpty(strHTML) == false)
                    {
                        HtmlDocument htmlDoc = new HtmlDocument();
                        htmlDoc.LoadHtml(strHTML);

                        HtmlNodeCollection divNodes = htmlDoc.DocumentNode.SelectNodes("//div[contains(@id, 'post-')]");
                        if (divNodes == null || divNodes.Count <= 0)
                        {
                            return(-1);
                        }

                        for (int j = 0; j < divNodes.Count; j++)
                        {
                            HtmlNode descNode     = null;
                            HtmlNode titleNode    = null;
                            HtmlNode authorNode   = null;
                            HtmlNode dateTimeNode = null;

                            try
                            {
                                if (divNodes[j] != null)
                                {
                                    HtmlAttribute divAttributeID = divNodes[j].Attributes["id"];
                                    if (divAttributeID != null)
                                    {
                                        titleNode = htmlDoc.GetElementbyId(divAttributeID.Value.Replace("post-", "headline-"));
                                        if (titleNode != null)
                                        {
                                            foreach (HtmlNode node in divNodes[j].ChildNodes)
                                            {
                                                if (node != null && node.Attributes["class"] != null)
                                                {
                                                    if (node.Attributes["class"].Value == "publication-info")
                                                    {
                                                        foreach (HtmlNode secondNode in node.ChildNodes)
                                                        {
                                                            if (secondNode != null && secondNode.Attributes["class"] != null)
                                                            {
                                                                if (secondNode.Attributes["class"].Value == "by-line")
                                                                {
                                                                    authorNode = secondNode;
                                                                }

                                                                if (secondNode.Attributes["class"].Value == "post-time")
                                                                {
                                                                    dateTimeNode = secondNode;
                                                                }
                                                            }
                                                        }
                                                    }

                                                    if (node.Attributes["class"].Value == "body-copy")
                                                    {
                                                        descNode = node;
                                                    }
                                                }
                                            }

                                            if (descNode != null && titleNode != null && authorNode != null && dateTimeNode != null)
                                            {
                                                String strUrl      = titleNode.Attributes["href"].Value.Trim();
                                                String strTitle    = titleNode.Attributes["title"].Value.Trim();
                                                String strDesc     = descNode.InnerText.Trim();
                                                String strAuthor   = authorNode.InnerText.Trim();
                                                String strDateTime = dateTimeNode.InnerText.Trim().Replace("posted ", "");

                                                strTechCrunchTitleList.Add(strTitle);
                                                strTechCrunchUrlList.Add(strUrl);
                                                strTechCrunchDescList.Add(strDesc);
                                                strTechCrunchAuthorList.Add(strAuthor);
                                                strTechCrunchDateTimeList.Add(strDateTime);

                                                nCount++;
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                return(nCount);
            }
            catch (Exception ex)
            {
                strTechCrunchTitleList.Clear();
                strTechCrunchUrlList.Clear();
                strTechCrunchDescList.Clear();
                strTechCrunchAuthorList.Clear();
                strTechCrunchDateTimeList.Clear();

                PInvokeAPI.OutputDebugString("Error In GetArticlesFromTechCrunch,ErrorMessage: " + ex.Message);

                return(-1);
            }
        }