/// <summary>根据指定时间返回出生日期</summary> /// <param name="birth">指定时间</param> /// <returns>根据指定时间返回出生日期</returns> public static string GetBirthDate(string birth) { if (Often.IsDate(birth)) { return(App.DateOften.ReFDateTime("{$Year}-{$Month}-{$day}", birth)); } return(""); }
/// <summary>返回开始与结束日期</summary> /// <param name="u">用户页面对象</param> /// <param name="sdate">返回开始日期</param> /// <param name="edate">返回结束日期</param> public static void LoadRequestSEDate(IUserPageInfo u, ref string sdate, ref string edate) { sdate = u.TeP("sdate"); edate = u.TeP("edate"); string ssdate = u.TeP("isdate"); if (Often.IsDate(ssdate)) { sdate = ssdate; } string sedate = u.TeP("iedate"); if (Often.IsDate(sedate)) { edate = sedate; } }
/// <summary>将采集到的日期转换成正常日期格式</summary> /// <param name="s">采集到的日期</param> /// <returns>将采集到的日期转换成正常日期格式</returns> public static string FormatDate(string s) { if (Often.IsDate(s)) { return(s); } try { string dates = s.Trim().Replace("年", "-"); dates = dates.Replace("月", "-"); dates = dates.Replace("日", " "); dates = dates.Replace("时", ":"); dates = dates.Replace("分", ":"); dates = dates.Replace("秒", ""); dates = dates.Replace(" ", " "); dates = dates.Replace(" ", " "); dates = dates.Replace(" ", " "); dates = dates.Replace(" ", " "); dates = dates.Replace(" ", " "); string ns = ""; string ys = "01"; string rs = "01"; string ss = "00"; string fs = "00"; string ms = "00"; bool iscontinue = false; int place = dates.IndexOf("-"); if (place > -1) { iscontinue = false; ns = dates.Substring(0, place); if (!IsDateNum(ns, "y")) { ns = ""; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } place = dates.IndexOf("-"); if (place > -1 && iscontinue) { iscontinue = false; ys = dates.Substring(0, place); if (!IsDateNum(ys, "m")) { ys = "01"; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } else if (iscontinue) { ys = dates; if (!IsDateNum(ys, "m")) { ys = "01"; } } place = dates.IndexOf(" "); if (place > -1 && iscontinue) { iscontinue = false; rs = dates.Substring(0, place); if (!IsDateNum(rs, "d")) { rs = "01"; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } else if (iscontinue) { rs = dates; if (!IsDateNum(rs, "d")) { rs = "01"; } } place = dates.IndexOf(":"); if (place > -1 && iscontinue) { iscontinue = false; ss = dates.Substring(0, place); if (!IsDateNum(ss, "h")) { ss = "00"; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } else if (iscontinue) { ss = dates; if (!IsDateNum(ss, "h")) { ss = "00"; } } place = dates.IndexOf(":"); if (place > -1 && iscontinue) { iscontinue = false; fs = dates.Substring(0, place); if (!IsDateNum(fs, "mi")) { fs = "00"; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } else if (iscontinue) { fs = dates; if (!IsDateNum(fs, "mi")) { fs = "00"; } } place = dates.IndexOf(":"); if (place > -1 && iscontinue) { iscontinue = false; ms = dates.Substring(0, place); if (!IsDateNum(ms, "s")) { ms = "00"; } else { iscontinue = true; } dates = dates.Remove(0, place + 1).Trim(); } else if (iscontinue) { ms = dates; if (!IsDateNum(ms, "s")) { ms = "00"; } } if (ns == "") { return(s); } return(ns + "-" + ys + "-" + rs + " " + ss + ":" + fs + ":" + ms); } catch { return(s); } }
/// <summary>根据当前Url与Url内容采集数据</summary> public void GatherOper() { int cindex = 0; while (NowUrl.Trim() != "" && ListLinkContent.Trim() != "") { if (!IsListLinkEcho(NowUrl)) { string ListLinkArea = ""; if (gi.ws.UrlRangeRule != "") { ListLinkArea = wapp.GatherApp.GetRegTxtString(ListLinkContent, gi.ws.UrlRangeRule, gi.ws.UrlRangeRuleIndex); lout.OT(1, "获取内容页链接列表范围匹配内容。[" + ListLinkArea.Length.ToString() + "]"); } else { ListLinkArea = ListLinkContent; } if (ListLinkArea.Trim() != "") { List <string> linklist = wapp.GatherApp.GetRegTxtList(ListLinkArea, gi.ws.UrlRule, gi.ws.UrlRuleIndex); lout.OT(1, "获取内容页链接匹配数组[" + linklist.Count.ToString() + "]"); for (int x = 0; x < linklist.Count; x++) { StartDate = DateTime.Now; EndDate = StartDate; string links = wapp.GatherApp.FormatUrl(NowUrl, linklist[x].Trim()); if (!IsContLinkEcho(links)) { string actlink = links; NowContLinkList.Add(actlink); string errs = ""; string conts = wapp.GatherApp.GetHttp(det, actlink, gi.ws.CodingMode, ref PageEncoding, ref PageCoding, ref errs); if (errs != "") { lout.OT(1, "获取内容页起始url内容失败,错误信息:" + errs + "。[Url:" + actlink + "]"); } else { lout.OT(1, "获取内容页起始url内容。[" + actlink + "][" + conts.Length.ToString() + "]"); } DataRow nsdr = gi.gdt.NewRow(); for (int si = 0; si < gi.wsilist.Count; si++) { string sconts = ""; if (gi.wsilist[si].ContentRangeRule != "") { sconts = wapp.GatherApp.GetRegTxtString(conts, gi.wsilist[si].ContentRangeRule, gi.wsilist[si].ContentRangeRuleIndex); } else { sconts = conts; } string sis = ""; if (gi.wsilist[si].ContentType == 2) { sis = wapp.GatherApp.FormatDate(Often.OutTxt(wapp.GatherApp.GetUnCode(wapp.GatherApp.GetRegsTxt(sconts, gi.wsilist[si].ContentRule, gi.wsilist[si].ContentRuleIndex), gi.wsilist[si].ContentCodeMode))); } else { sis = wapp.GatherApp.GetUnCode(wapp.GatherApp.GetRegsTxt(sconts, gi.wsilist[si].ContentRule, gi.wsilist[si].ContentRuleIndex), gi.wsilist[si].ContentCodeMode); } if (gi.wsilist[si].ContentType == 1 && Often.IsNum(sis)) { nsdr[si] = sis; } else if (gi.wsilist[si].ContentType == 2 && Often.IsDate(sis)) { nsdr[si] = sis; } else { nsdr[si] = sis; } if (sis != "") { lout.OT(1, "[" + gi.wsilist[si].ListTitle + "(" + gi.wsilist[si].ListCode + ")]内容:[" + sis + "]采集成功!"); } } gi.gdt.Rows.Add(nsdr); GatherCount++; if (GatherCount >= gi.ws.GatherMaxNum) { return; } #region 保存采集内存表中的信息到数据库 if (gi.gdt.Rows.Count > 999) { string savefile = GetExcelSaveFileName(); lout.OT(1, "保存数据到Excel文件操作开始[文件名:" + savefile + "]..."); wapp.Excel ex = new wapp.Excel(); ex.DataTableToExcel(gi.gdt); ex.WriteFile(savefile); gi.gdt.Clear(); lout.OT(1, "保存数据到Excel文件操作结束[文件名:" + savefile + "]"); } #endregion } } } } string listurl = NowUrl; NowUrlList.Add(NowUrl); NowUrl = ""; if (gi.ws.IsNext == 1) { if (gi.ws.NextMode == 1) { #region 采集内容链接列表分页(列表分页为单页采集模式) if (CentUrlList.Count > 0 && cindex < CentUrlList.Count) { NowUrl = CentUrlList[cindex].Trim(); cindex++; } #endregion } else { #region 采集内容链接列表分页(列表分页为多页采集模式) if (gi.ws.NextRangeRule != "") { string s = wapp.GatherApp.GetRegTxtString(ListLinkContent, gi.ws.NextRangeRule, gi.ws.NextRangeRuleIndex); if (s != "") { s = wapp.GatherApp.GetRegsTxt(s, gi.ws.NextRule, gi.ws.NextRuleIndex); if (s != "") { NowUrl = wapp.GatherApp.GetUrls(wapp.GatherApp.FormatUrl(listurl, s)); } } } else { string s = wapp.GatherApp.GetRegsTxt(ListLinkContent, gi.ws.NextRule, gi.ws.NextRuleIndex); if (s != "") { NowUrl = wapp.GatherApp.GetUrls(wapp.GatherApp.FormatUrl(listurl, s)); } } #endregion } if (NowUrl != "" && !IsListLinkEcho(NowUrl)) { string errs = ""; ListLinkContent = wapp.GatherApp.GetHttp(det, NowUrl, gi.ws.CodingMode, ref PageEncoding, ref PageCoding, ref errs); if (errs != "") { ListLinkContent = ""; lout.OT(1, "列表页采集失败,错误信息:" + errs + ",[Url:" + NowUrl + "]"); } } else { ListLinkContent = ""; } } NowUrlCount++; } }