/// <summary> /// 根据URL抓取标题 /// </summary> /// <param name="task">HTML标题获取客户端任务池</param> /// <param name="url">URL</param> internal static void Crawl(AutoCSer.Net.HtmlTitle.HttpTask task, string url) { UrlTitle urlTitle = new UrlTitle { url = url }; Interlocked.Increment(ref currentCount); task.Get(url, urlTitle.onTitle); }
static void Main(string[] args) { Console.WriteLine(@"http://www.AutoCSer.com/Index.html "); using (AutoCSer.Net.HtmlTitle.HttpTask task = new AutoCSer.Net.HtmlTitle.HttpTask(4, 15, AutoCSer.Memory.BufferSize.Kilobyte16)) { #if DotNetStandard System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); #endif UrlTitle.Crawl(task, "http://www.AutoCSer.com/"); UrlTitle.Crawl(task, "http://www.51nod.com/"); UrlTitle.Crawl(task, "http://www.cnblogs.com/asxinyu/"); UrlTitle.Crawl(task, "http://www.baidu.com/"); UrlTitle.Crawl(task, "http://www.163.com/"); UrlTitle.Crawl(task, "http://mail.163.com/"); UrlTitle.Crawl(task, "http://www.qq.com/"); UrlTitle.Crawl(task, "http://www.zhihu.com/"); UrlTitle.Crawl(task, "http://www.cnblogs.com/"); UrlTitle.Crawl(task, "http://www.csdn.net/"); UrlTitle.Crawl(task, "http://bbs.csdn.net/"); UrlTitle.Crawl(task, "http://www.csharpkit.com/"); UrlTitle.Crawl(task, "https://www.51nod.com/"); UrlTitle.Crawl(task, "https://www.163.com/"); UrlTitle.Crawl(task, "https://mail.163.com/"); UrlTitle.Crawl(task, "https://www.zhihu.com/"); UrlTitle.Crawl(task, "https://www.cnblogs.com/"); Console.WriteLine(@"Press quit to exit."); Console.WriteLine(@"Press url to crawl title."); do { string url = Console.ReadLine(); if (url == "quit") { break; } UrlTitle.Crawl(task, url); }while (true); } }