Example #1
0
 static void ht_FileWatchEvent(object sender, CompleteEventArgs e)
 {
     timer2.Stop();
     Console.WriteLine("加载时间" + i.ToString() + "ms");
     list = httpSer.Result2Deserializer(e.Node).ToList();
     foreach (var item in list)
     {
         Console.WriteLine("sID{0} artistID{1},aid{2},lrc:{3}", item.sid,item.artist_id,item.aid, item.lrc);
     }
     HttpHelper ht = new HttpHelper();
     string select = Console.ReadLine();
     Model.Result2 result2 = list.FirstOrDefault(c => c.sid.ToString() == select);
     ht.CreatePostHttpResponse(result2.lrc);
     ht.FileWatchEvent += ht_FileWatchEvent2;
 }
Example #2
0
        static void Main(string[] args)
        {
            while (true)
            {

                HttpHelper ht = new HttpHelper();
                string keyWord = "笔记";
                string url = "http://geci.me/api/lyric/" + keyWord;
                ht.CreatePostHttpResponse(url);
                ht.FileWatchEvent += ht_FileWatchEvent;
                timer2.Interval = 0.01;
                timer2.Elapsed += timer2_Elapsed;
                timer2.Start();

                Console.ReadKey();
            }
        }
Example #3
0
        public static void GetTieba(string url)
        {
            var httpResult = new HttpHelper().GetHtml(new HttpItem()
            {
                URL = "https://tieba.baidu.com/f?kw=%E6%8A%97%E5%8E%8B&ie=utf-8&pn=" + url + ""
            });

            if (httpResult.StatusCode == System.Net.HttpStatusCode.OK)
            {
                HtmlDocument hd = new HtmlDocument();
                hd.LoadHtml(httpResult.Html);
                var titleList = hd.DocumentNode.SelectNodes(".//div[@class='col2_right j_threadlist_li_right ']");
                foreach (var item in titleList)
                {
                    var id = item.SelectSingleNode("./div[1]/div[1]/a[1]").Attributes["href"].Value;
                    id = id.Substring(3, id.Length - 3);                                 //贴吧ID
                    var title = item.SelectSingleNode("./div[1]/div[1]/a[1]").InnerText; //标题
                    if (id.Length == 10)
                    {
                        Console.WriteLine("已获取到标题" + title + "");
                        bool ok = SqlHelper.Is_Tid(id);
                        if (ok)
                        {
                            Console.WriteLine("正在添加数据" + id + "");
                            var username = item.SelectSingleNode("./div[1]/div[2]/span").Attributes["title"].Value;
                            username = username.Substring(6, username.Length - 6); //用户名
                            var userid = item.SelectSingleNode("./div[1]/div[2]/span").Attributes["data-field"].Value;
                            userid = userid.Substring(21, userid.Length - 22);     //用户id
                            bool Insert_ok = SqlHelper.InsertTieba(new Model.Tieba()
                            {
                                Tid      = id,
                                title    = title,
                                username = username,
                                userid   = userid
                            });
                            if (Insert_ok)
                            {
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("添加数据成功");
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.WriteLine("添加数据失败");
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("已存在数据");
                        }
                    }
                }
                //var pageurl = hd.DocumentNode.SelectSingleNode(".//a[@class='next pagination-item ']").Attributes["href"].Value;
                //pageurl = "https://" + pageurl;
                //GetTieba(pageurl);
                Console.WriteLine("已写入全部数据");
                Console.WriteLine(Convert.ToInt32(url) + 50);
                GetTieba((Convert.ToInt32(url) + 50).ToString());
                Console.ReadKey();
            }
        }