Exemplo n.º 1
0
        /// <summary>
        /// 爬虫单元线程
        /// </summary>
        private void CrawlerThread(object obj)
        {
            TaskList tasklist = obj as TaskList;
            string   changeIp = null;

            while (tasklist.GetSerplusNum() > 0)
            {
                try
                {
                    string companyName     = tasklist.GetNext();
                    var    transitionModel = CrawlerWork(companyName, changeIp);
                    changeIp = transitionModel.Value;
                    //if (!SqlHelper.InserInfo(transitionModel.Key)) OutLog(companyName + "写入数据库错误。");
                    if (!DoSql.InsertBj(transitionModel.Key))
                    {
                        OutLog(companyName + "写入数据库错误。");
                    }
                }
                catch (Exception e)
                {
                    OutLog(e.Message);
                }
            }
            OutLog("线程【" + Thread.CurrentThread.ManagedThreadId + "】爬取任务结束");
            tasklist.StopThead();
        }
Exemplo n.º 2
0
 public string SingelCrawlerThread(string searchText, ListBox list, TextBox listbox,
                                   string changeIp = null)
 {
     ListLogs = listbox;
     try
     {
         string companyName     = searchText;
         var    transitionModel = CrawlerWork(companyName, changeIp);
         changeIp = transitionModel.Value;
         if (!DoSql.InsertBj(transitionModel.Key))
         {
             OutLog(companyName + ",写入数据库错误。");
         }
     }
     catch (Exception e)
     {
         OutLog(e.Message);
     }
     OutLog("线程【" + Thread.CurrentThread.ManagedThreadId + "】爬取任务结束");
     return(changeIp);
 }