/// <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); } }
/// <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); } }
/// <summary> /// 重新绑定最近的 Post 列表 /// </summary> private void ReBindRecentPost() { /* 重新绑定数据 */ recentPostList.Clear(); try { recentPostList = new List <MetaWeblogEntity.Post>(metaWeblog.getRecentPosts(String.Empty, strUserName, strPassword, ConfigEntity.Recent_Post_Count)); if (recentPostList != null && recentPostList.Count > 0) { List <Int32> indexList = new List <Int32>(); for (int i = 0; i < recentPostList.Count; i++) { try { MetaWeblogEntity.Post post = metaWeblog.getPost(recentPostList[i].postid.ToString(), strUserName, strPassword); if (recentPostList[i].postid.ToString() == post.postid.ToString()) { indexList.Add(i); } } catch (Exception ex) { } } List <MetaWeblogEntity.Post> tmpRecentPostList = new List <MetaWeblogEntity.Post>(); dgvRecent.Rows.Clear(); for (int i = 0; i < indexList.Count; i++) { dgvRecent.Rows.Add(i + 1, recentPostList[indexList[i]].title, strUserName, recentPostList[indexList[i]].dateCreated.ToString("yyyy-MM-dd HH:mm")); tmpRecentPostList.Add(recentPostList[indexList[i]]); } recentPostList.Clear(); recentPostList.AddRange(tmpRecentPostList); } } catch (Exception ex) { PInvokeAPI.OutputDebugString("Error In ReBindRecentPost,ErrorMessage: " + ex.Message); recentPostList.Clear(); } }
/// <summary> /// 从 C++ 博客网页上获取到此条博客的标题 /// </summary> /// <param name="strHTML"></param> /// <param name="strOuterHtml"></param> /// <param name="strInnerHtml"></param> /// <param name="strInnerText"></param> /// <returns></returns> public static bool GetBlogsTitleFromCppBlog(String strHTML, ref String strOuterHtml, ref String strInnerHtml, ref String strInnerText) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; try { HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(strHTML); HtmlNodeCollection parentNodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='post']"); if (parentNodes.Count <= 0) { return(false); } HtmlNode parentNode = parentNodes[0]; HtmlNode node = parentNode.SelectSingleNode("//a[@id='viewpost1_TitleUrl']"); if (node != null) { strOuterHtml = node.OuterHtml; strInnerHtml = node.InnerHtml; strInnerText = node.InnerText; return(true); } else { return(false); } } catch (Exception ex) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; PInvokeAPI.OutputDebugString("Error In GetBlogsTitleFromCppBlog,ErrorMessage: " + ex.Message); return(false); } }
/// <summary> /// 从博客园博客网页上获取到此条博客的标题 /// </summary> /// <param name="strHTML"></param> /// <param name="strOuterHtml"></param> /// <param name="strInnerHtml"></param> /// <param name="strInnerText"></param> /// <returns></returns> public static bool GetBlogsTitleFromCnBlogs(String strHTML, ref String strOuterHtml, ref String strInnerHtml, ref String strInnerText) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; try { HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(strHTML); HtmlNode titleNode = htmlDoc.GetElementbyId("cb_post_title_url"); if (titleNode == null) { titleNode = htmlDoc.GetElementbyId("ctl01_lnkTitle"); } if (titleNode != null) { strOuterHtml = titleNode.OuterHtml; strInnerHtml = titleNode.InnerHtml; strInnerText = titleNode.InnerText; return(true); } else { return(false); } } catch (Exception ex) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; PInvokeAPI.OutputDebugString("Error In GetBlogsTitleFromCnBlogs,ErrorMessage: " + ex.Message); return(false); } }
/// <summary> /// 从博客园博客网页上获取到此条博客的内容 /// </summary> /// <param name="strHTML"></param> /// <param name="strOuterHtml"></param> /// <param name="strInnerHtml"></param> /// <param name="strInnerText"></param> /// <returns></returns> public static bool GetBlogsBodyFromCnBlogs(String strHTML, ref String strOuterHtml, ref String strInnerHtml, ref String strInnerText) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; try { HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(strHTML); HtmlNode bodyNode = htmlDoc.GetElementbyId("cnblogs_post_body"); if (bodyNode != null) { strOuterHtml = bodyNode.OuterHtml; strInnerHtml = bodyNode.InnerHtml; strInnerText = bodyNode.InnerText; return(true); } else { return(false); } } catch (Exception ex) { strOuterHtml = String.Empty; strInnerHtml = String.Empty; strInnerText = String.Empty; PInvokeAPI.OutputDebugString("Error In GetBlogsBodyFromCnBlogs,ErrorMessage: " + ex.Message); return(false); } }
/// <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); } }
/// <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); } }
/// <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); } }
/// <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); } }