public static void Getboke()//获取新闻列表 { var httpResult = new HttpHelper().GetHtml(new HttpItem() { URL = "https://news.cnblogs.com/NewsAjax/GetRecentNews?itemCount=20000" }); if (httpResult.StatusCode == System.Net.HttpStatusCode.OK) { HtmlDocument hd = new HtmlDocument(); hd.LoadHtml(httpResult.Html); var NewsList = hd.DocumentNode.SelectNodes("li/a[@href][1]");//标题 foreach (var item in NewsList) { var NewsId = item.Attributes["href"].Value; NewsId = NewsId.Substring(3, NewsId.Length - 4); if (NewsId.Length == 6) { Console.WriteLine("已获取ID" + NewsId + "新闻"); bool ok = SqlHelper.Is_Id(NewsId); if (ok) { Console.WriteLine("正在添加数据" + NewsId + ""); string code = Accserver.GetNews(NewsId); if (code == "success") { Console.WriteLine("添加数据成功"); } else if (code == "error") { Console.WriteLine("写入数据库失败"); } else { Console.WriteLine("写入失败," + code + "状态码"); } } else { Console.WriteLine("已存在数据"); } } else { Console.WriteLine("已全部写入成功"); } } Console.ReadLine(); } }
static void Main(string[] args) { Accserver.GetTieba("0"); }