/// <summary> /// /// </summary> /// <param name="spiderinfo"></param> /// <returns></returns> public bool Control(Spiderinfo spiderinfo) { bool flg = false; #region 爬虫监控系统 string insertSql = string.Format("insert ignore into spiderinfo(SpiderProgramName,TaskName,SiteName,TemplateName,StartDT,EndDT,RequestMount,CatchMount,StoreMount,ProxyRequestMount,ProxyPercent,VertifyMount,VertifyPercent,TotalMount,TotalLength,IPAddress,Ext) values('{0}','{1}','{2}','{3}','{4}','{5}',{6},{7},{8},{9},{10},{11},{12},{13},{14},'{15}','{16}')", spiderinfo.SpiderProgramName, spiderinfo.TaskName, spiderinfo.SiteName, spiderinfo.TemplateName, spiderinfo.StartDT, spiderinfo.EndDT, spiderinfo.RequestMount, spiderinfo.CatchMount, spiderinfo.StoreMount, spiderinfo.ProxyRequestMount, spiderinfo.ProxyPercent, spiderinfo.VertifyMount, spiderinfo.VertifyPercent, spiderinfo.TotalMount, spiderinfo.TotalLength, spiderinfo.IPAddress, spiderinfo.Ext); int itryMax = 3; while (itryMax > 0) { int iflg = MySqlHelp.Insert(AliyunConn, insertSql, spiderinfo.TaskName + "插入数据失败记录.txt"); if (iflg >= 0) { itryMax = 0; flg = true; } else { itryMax--; } string checkInfo = string.Format("爬虫:{0} 请求量:{1} 抓取量:{2} 入库量:{3} 代理请求量:{4} 代理成功率:{5} 打码次数:{6} 成功打码:{7} 打码成功率:{8} 总抓取量:{9} 时间:{10}", spiderinfo.TaskName, spiderinfo.RequestMount, spiderinfo.CatchMount, spiderinfo.StoreMount, spiderinfo.ProxyRequestMount, spiderinfo.ProxyPercent, spiderinfo.VertifyMount, spiderinfo.VertifyTrueMount, spiderinfo.VertifyPercent, spiderinfo.TotalMount, DateTime.Now); Console.WriteLine("【{0}】{1}", iflg, checkInfo); CLog.DiaryLog(checkInfo, spiderinfo.TaskName + "(每半小时统计一次)_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"); } #endregion return(flg); }
/// <summary> /// 数据库插入操作 /// </summary> /// <param name="conn">数据库连接</param> /// <param name="sql">插入语句</param> /// <param name="errorFile">错误记录的文件名</param> /// <param name="parameters">参数列表化</param> /// <returns>-101为插入失败</returns> public int Insert(string conn, string sql, string errorFile, params MySqlParameter[] parameters) { return(MySqlHelp.Insert(conn, sql, errorFile)); }