private void PopulateAndSaveRegularExpression(RegexInfo toSave) { toSave.Options = this.Options; toSave.Regex = this.RegularExpression; toSave.ReplacePattern = this.ReplacePattern; model.SaveRegexs(CurrentRegexs); }
public string CCOUNT(RegexInfo reg, string strText) { if (EntityFactory.MainHeroView == null || !_propertyRatio.ContainsKey("CCOUNT")) { return(null); } if (_propertyRatio["CCOUNT"].Count == 0) { return(null); } int ratio = _propertyRatio["CCOUNT"][0].nRatio; _propertyRatio["CCOUNT"].RemoveAt(0); if (!_dicChargeCount.ContainsKey(ratio)) { return("0"); } chargeValue_Info valueInfo = _dicChargeCount[ratio]; int ShowNum = valueInfo.chargeCount; string appendNum = string.Format("{0:D1}", ShowNum); return(appendNum); }
private void changeFunc() { this.txtStatus.ForeColor = Color.Blue; this.txtStatus.Text = "修改信息:正在修改..."; Application.DoEvents(); RegexInfo myLoginInfo = new RegexInfo(); if (this.txtChangeTo.Text != "") { if (myLoginInfo.isMailAddress(this.txtChangeTo.Text)) { ManageDB myManageDB = new ManageDB(); myManageDB.UpdateDB("用户管理", "email", this.txtChangeTo); TimeDelay myTimeDelay = new TimeDelay(); this.btnOK.Enabled = false; this.btnCancel.Enabled = false; myTimeDelay.closingCurrentWindowDelay(3, this.txtStatus, this, "修改信息:修改成功!", ""); } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "修改信息:修改失败!邮箱地址不合法!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "修改信息:修改失败,所有项不能为空!"; } }
private void dataGridViewRegexs_MouseDoubleClick(object sender, MouseButtonEventArgs e) { RegexInfo toLoad = CurrentRegexs[dataGridViewRegexs.SelectedIndex]; SetCurrentRegexInfo(toLoad, true, true); e.Handled = true; }
public void AddIncludeRegex (string regex, int valueGroupIndex, int pluralGroupIndex, string regexOptions, StringEscaping.EscapeMode escapeMode) { Regex rx = new Regex (regex, ParseOptions (regexOptions)); RegexInfo ri = new RegexInfo (); ri.Regex = rx; ri.ValueGroupIndex = valueGroupIndex; ri.PluralGroupIndex = pluralGroupIndex; ri.EscapeMode = escapeMode; regexes.Add (ri); }
public void AddIncludeRegex(string regex, int valueGroupIndex, int pluralGroupIndex, string regexOptions, StringEscaping.EscapeMode escapeMode) { Regex rx = new Regex(regex, ParseOptions(regexOptions)); RegexInfo ri = new RegexInfo(); ri.Regex = rx; ri.ValueGroupIndex = valueGroupIndex; ri.PluralGroupIndex = pluralGroupIndex; ri.EscapeMode = escapeMode; regexes.Add(ri); }
public void start() { RegexInfo 总条数正则 = new RegexInfo("共找到<strong class=\"number orange\">([\\d]*)</strong>条", "$1"); RegexInfo cityRegexInfo = new RegexInfo("<div class=\"onCont\" id=\"c01\"[^<>]*>((?:(?!</div>).)*)</div>", "$1"); RegexInfo cityRegexInfo2 = new RegexInfo("(<a href=\"[^\"]+\"[^<>]*>[^<>]+</a>)", "$1"); Dictionary <string, RegexInfo> cityRegexDic = new Dictionary <string, RegexInfo>(); cityRegexDic.Add("城市列表Text", cityRegexInfo); Dictionary <string, List <string> > dicCitylistText = SpiderHelp.GetHtmlByRegex("http://soufun.com/SoufunFamily.htm", "utf-8", cityRegexDic, WebsiteManager.GetWebById(WebsiteManager.搜房网_ID), CityId); string cityText = dicCitylistText["城市列表Text"].Count > 0 ? dicCitylistText["城市列表Text"][0] : ""; cityRegexDic.Add("城市列表", cityRegexInfo2); Dictionary <string, List <string> > dicCitylist = SpiderHelp.GetStrByRegex(cityText, cityRegexDic); List <string> cityList = dicCitylist["城市列表"]; StringBuilder citySb = new StringBuilder(); cityRegexDic.Add("总条数", 总条数正则); List <string> list2 = new List <string>(); foreach (string cityInfoStr in cityList) { RegexInfo regexCityName = new RegexInfo("<a href=\"[^\"]+\"[^<>]*>([^<>]+)</a>", "$1"); RegexInfo regexCityUrl = new RegexInfo("<a href=\"([^\"]+)\"[^<>]*>[^<>]+</a>", "$1"); Dictionary <string, RegexInfo> cityRegexDic2 = new Dictionary <string, RegexInfo>(); cityRegexDic2.Add("regexCityName", regexCityName); cityRegexDic2.Add("regexCityUrl", regexCityUrl); Dictionary <string, List <string> > dicCityInfo = SpiderHelp.GetStrByRegex(cityInfoStr, cityRegexDic2); string cityName = StringHelp.TrimBlank(dicCityInfo["regexCityName"].Count > 0 ? dicCityInfo["regexCityName"][0] : ""); string cityUrl = dicCityInfo["regexCityUrl"].Count > 0 ? dicCityInfo["regexCityUrl"][0] : ""; string execStr = " exec 往网站爬取配置表添加配置信息 '{0}','{1}','{2}','{3}','{4}',{5},{6}"; 城市表 city = CityManager.Get城市_byLike城市名称(cityName); if (city != null && SpiderWebConfigManager.get网站爬取配置_by城市ID_网站ID(city.ID, WebsiteManager.搜房网_ID) == null)//&& { string houseUrl1 = cityUrl.Replace("http://", "http://esf.").TrimEnd('/'); if (city.城市名称.Contains("北京")) { houseUrl1 = houseUrl1.Replace("bj.", ""); } string houseUrl2 = houseUrl1 + "/house/h316-j3100-w32/"; Dictionary <string, List <string> > dicCountlistText = SpiderHelp.GetHtmlByRegex(houseUrl2, "gbk", cityRegexDic, WebsiteManager.GetWebById(WebsiteManager.搜房网_ID), CityId); string count = dicCountlistText["总条数"].Count > 0 ? dicCountlistText["总条数"][0] : ""; if (!string.IsNullOrEmpty(count)) { execStr = string.Format(execStr, WebsiteManager.搜房网, city.城市名称, houseUrl1, houseUrl2, "", "4000", "2000"); citySb.Append(execStr).Append("\r\n"); list2.Add(execStr); } } } string result = citySb.ToString(); }
public static RegexInfo GetRegexInfoByXmlName(string name, string webName, string cityName = "NewDataSpider", int?number = null) { //根据城市+网站获取xml文件 XmlDocument RegexInfoConfig = new XmlDocument(); if (number != null) { cityName = cityName + "_" + number.ToString(); } string key = webName + "." + cityName; //如果未加载过在加载一次 缓存到字典 if (!RegexInfoXmlDic.ContainsKey(key)) { string configPath = AppDomain.CurrentDomain.BaseDirectory + "RegexInfoXML/" + webName + "/" + cityName + ".xml"; RegexInfoConfig.Load(configPath); RegexInfoXmlDic[key] = RegexInfoConfig; } else { RegexInfoConfig = RegexInfoXmlDic[key]; } RegexInfo obj = new RegexInfo(); XmlNode RegexInfoXml = RegexInfoConfig.SelectSingleNode("/RegexInfos/regexinfo[@Name='" + name + "']"); if (RegexInfoXml != null) { XmlNode regex = RegexInfoXml.SelectSingleNode("regex"); XmlNode index = RegexInfoXml.SelectSingleNode("index"); obj.RegexStr = regex.InnerText.DecodeField(); obj.RegexIndex = index.InnerText; XmlNode regexinfolist = RegexInfoXml.SelectSingleNode("regexinfolist"); if (regexinfolist != null) { XmlNodeList regexinfos = regexinfolist.SelectNodes("regexinfo"); foreach (XmlNode node in regexinfos) { XmlNode _regex = node.SelectSingleNode("regex"); XmlNode _index = node.SelectSingleNode("index"); RegexInfo _obj = new RegexInfo(_regex.InnerText.DecodeField(), _index.InnerText.DecodeField()); obj.RegexInfoList.Add(_obj); } } } else { obj.RegexStr = ""; obj.RegexIndex = "$1"; } return(obj); }
private void listBox_0_SelectedIndexChanged(object sender, EventArgs e) { this.method_0(); if (!this.button_0.Enabled) { int selectedIndex = this.listBox_0.SelectedIndex; if (selectedIndex != -1) { this.textBox_1.Text = this.propertyInfo_0[selectedIndex].Name; this.textBox_2.Text = this.hashtable_0[this.propertyInfo_0[selectedIndex].Name].ToString(); if (this.propertyInfo_0[selectedIndex].PropertyType != typeof(RegexInfo)) { this.comboBox_1.Text = "Other"; try { this.textBox_0.Text = this.propertyInfo_0[selectedIndex].GetValue(this.ruleConfigInfo_0, null).ToString(); this.textBox_3.Text = ""; } catch { this.textBox_0.Text = ""; this.textBox_3.Text = ""; } } else { RegexInfo value = (RegexInfo)this.propertyInfo_0[selectedIndex].GetValue(this.ruleConfigInfo_0, null) ?? new RegexInfo(); this.comboBox_1.Text = value.Method; this.textBox_0.Text = value.Pattern.Trim().Replace("\r", "").Replace("\n\n", "\n").Replace("\n\n", "\n").Replace("\n\n", "\n").Replace("\n", "\r\n"); this.textBox_3.Text = value.FilterPattern.Replace("\r", "").Replace("\n\n", "\n").Replace("\n\n", "\n").Replace("\n\n", "\n").Replace("\n", "\r\n"); this.checkBox_0.Checked = false; this.checkBox_1.Checked = false; if (value.Options == RegexOptions.IgnoreCase) { this.checkBox_0.Checked = true; } if (value.Options == RegexOptions.Singleline) { this.checkBox_1.Checked = true; } if (value.Options == (RegexOptions.IgnoreCase | RegexOptions.Singleline)) { this.checkBox_0.Checked = true; this.checkBox_1.Checked = true; } } } } }
public void start() { 网站表 webObj = WebsiteManager.GetWebById(WebsiteManager.城市房产_ID); RegexInfo 总页数正则 = new RegexInfo("<div class=\"[^\"]*\"><span class='fl mr'>\\d+/(\\d+)</span>", "$1"); Dictionary <string, RegexInfo> 根页面正则字典集合 = new Dictionary <string, RegexInfo>(); 根页面正则字典集合.Add("总页数", 总页数正则); RegexInfo cityRegexInfo = new RegexInfo("(<a[^<>]+href=[\",']{1,1}http\\://[^\\.]+.cityhouse.cn[\",']{1,1}[^<>]*>[^<>]+</a>)", "$1"); //cityRegexInfo.RegexInfoList.Add(new RegexInfo("(<a[^<>]+href='http\\://[^\\.]+.cityhouse.cn'[^<>]*>[^<>]+</a>)", "$1")); Dictionary <string, RegexInfo> cityRegexDic = new Dictionary <string, RegexInfo>(); cityRegexDic.Add("城市列表", cityRegexInfo); Dictionary <string, List <string> > dicCitylistText = SpiderHelp.GetHtmlByRegex("http://www.cityhouse.cn/city.html", "utf-8", cityRegexDic, WebsiteManager.GetWebById(WebsiteManager.城市房产_ID), CityId); List <string> cityList = dicCitylistText["城市列表"]; StringBuilder citySb = new StringBuilder(); StringBuilder citySb2 = new StringBuilder(); foreach (string cityInfoStr in cityList) { RegexInfo regexCityName = new RegexInfo("<a[^<>]+href=[\",']{1,1}http\\://[^\\.]+.cityhouse.cn[\",']{1,1}[^<>]*>([^<>]+)</a>", "$1"); RegexInfo regexCityUrl = new RegexInfo("<a[^<>]+href=[\",']{1,1}(http\\://[^\\.]+.cityhouse.cn)[\",']{1,1}[^<>]*>[^<>]+</a>", "$1"); Dictionary <string, RegexInfo> cityRegexDic2 = new Dictionary <string, RegexInfo>(); cityRegexDic2.Add("regexCityName", regexCityName); cityRegexDic2.Add("regexCityUrl", regexCityUrl); Dictionary <string, List <string> > dicCityInfo = SpiderHelp.GetStrByRegex(cityInfoStr, cityRegexDic2); string cityName = StringHelp.TrimBlank(dicCityInfo["regexCityName"].Count > 0 ? dicCityInfo["regexCityName"][0] : ""); string cityUrl = dicCityInfo["regexCityUrl"].Count > 0 ? dicCityInfo["regexCityUrl"][0] : ""; string execStr = " exec 往网站爬取配置表添加配置信息 '{0}','{1}','{2}','{3}','{4}',{5},{6}"; 城市表 city = CityManager.Get城市_byLike城市名称(cityName); if (city != null && !citySb2.ToString().Contains(city.城市名称) && !citySb.ToString().Contains(city.城市名称) && SpiderWebConfigManager.get网站爬取配置_by城市ID_网站ID(city.ID, WebsiteManager.城市房产_ID) == null) { Dictionary <string, List <string> > 根页面正则字典集合结果 = SpiderHelp.GetHtmlByRegex(cityUrl + "/forsale/flist.html?ob=10", "utf-8", 根页面正则字典集合, webObj, CityId, referer: cityUrl + "/forsale/flist.html?ob=10"); execStr = string.Format(execStr, WebsiteManager.城市房产, city.城市名称, cityUrl, cityUrl + "/forsale/flist.html?ob=10", "", "2000", "2000"); if (根页面正则字典集合结果["总页数"].Count() < 1) { citySb2.Append(execStr).Append("\r\n"); continue; } citySb.Append(execStr).Append("\r\n"); } } string result = citySb.ToString(); string result2 = citySb2.ToString(); 导出任务计划配置文件(); }
private void myLoginFunc() { RegexInfo myLoginInfo = new RegexInfo(); ManageDB myManageDB = new ManageDB(); this.txtStatus.ForeColor = Color.Blue; this.txtStatus.Text = "重置信息:重置中..."; Application.DoEvents(); if (this.txtUserName.Text != "" && this.txtUserEmail.Text != "") { if (myManageDB.checkUserName(this.txtUserName.Text)) { if (myLoginInfo.isMailAddress(this.txtUserEmail.Text)) { if (myManageDB.userMailToResetPassword(this.txtUserName.Text, this.txtUserEmail.Text)) { TimeDelay myTimeDelay = new TimeDelay(); this.btnOK.Enabled = false; this.btnCancel.Enabled = false; myTimeDelay.closingCurrentWindowDelay(3, this.txtStatus, this, "重置信息:验证成功,即将开始重置...", ""); UserChangePSD myUserChangePSD = new UserChangePSD(); myUserChangePSD.Show(); } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "重置信息:重置失败,请确认邮箱是否填写正确!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "重置信息:重置失败!邮箱地址不合法!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "重置信息:重置失败,用户名不存在!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "重置信息:重置失败,用户名和邮箱均不能为空!"; } }
private void buttonSaveAs_Click(object sender, RoutedEventArgs e) { SaveWindow saveWindow = new SaveWindow("Save Regular Expression"); saveWindow.ShowDialog(); if (saveWindow.DialogResult.GetValueOrDefault()) { RegexInfo regexInfo = new RegexInfo { Id = Guid.NewGuid(), Name = saveWindow.Name }; CurrentRegexs.Add(regexInfo); PopulateAndSaveRegularExpression(regexInfo); SetCurrentRegexInfo(regexInfo, false, false); } RefreshLoadedRegexsView(); }
private void buttonRenameRegularExpression_Click(object sender, RoutedEventArgs e) { if (dataGridViewRegexs.SelectedItems.Count == 1) { RegexInfo regexInfo = (RegexInfo)dataGridViewRegexs.SelectedItems[0]; SaveWindow renameWindow = new SaveWindow("Rename Regular Expression") { Name = regexInfo.Name }; renameWindow.ShowDialog(); if (renameWindow.DialogResult.GetValueOrDefault()) { regexInfo.Name = renameWindow.Name; model.SaveRegexs(CurrentRegexs); RefreshLoadedRegexsView(); SetToolWindowTitle(); } } }
private void btnOK_Click(object sender, EventArgs e) { if (this.stbProName.Text != "") { RegexInfo myLoginInfo = new RegexInfo(); if (myLoginInfo.isProjectName(this.stbProName.Text)) { if (myLoginInfo.isProjectLocation(this.stbLocation.Text)) { projectLocation = this.stbLocation.Text + "\\" + this.stbProName.Text; if (Array.IndexOf <string>(MainForm.root_paths, projectLocation) != -1) { MessageBox.Show("打开工程名称冲突,请修改工程名称!", "消息提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.IsCreateSolution = true; createFolder(projectLocation); this.txtStatus.ForeColor = Color.Green; this.txtStatus.Text = "创建信息:创建成功!"; this.Close(); this.DialogResult = DialogResult.OK; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,请正确填写项目路径!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,请正确填写项目名称!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,项目名称不能为空!"; } }
private void SetCurrentRegexInfo(RegexInfo current, bool clearMatch, bool switchTab) { this.CurrentRegexInfo = current; if (this.CurrentRegexInfo != null) { this.RegularExpression = current.Regex ?? ""; this.ReplacePattern = current.ReplacePattern ?? ""; this.Options = current.Options; buttonSaveTest.IsEnabled = true; buttonSaveTestAs.IsEnabled = true; tabItemTestCases.Visibility = System.Windows.Visibility.Visible; this.dataGridViewTestCases.ItemsSource = CurrentRegexInfo.TestCaseInfos; if (this.CurrentRegexInfo.TestCaseInfos != null && this.CurrentRegexInfo.TestCaseInfos.Count > 0) { SetCurrentTestCaseInfo(this.CurrentRegexInfo.TestCaseInfos[0], false); } else if (clearMatch) { SetCurrentTestCaseInfo(null, false); } } else { this.RegularExpression = ""; this.ReplacePattern = ""; this.Options = RegexOptions.None; buttonSaveTest.IsEnabled = false; buttonSaveTestAs.IsEnabled = false; tabItemTestCases.Visibility = System.Windows.Visibility.Hidden; this.dataGridViewTestCases.ItemsSource = null; if (clearMatch) { SetCurrentTestCaseInfo(null, false); } } SetToolWindowTitle(); if (switchTab) { tabControlRegex.SelectedIndex = 0; } }
public void start() { RegexInfo cityRegexInfo = new RegexInfo("<dl id=\"clist\">((?:(?!</dl>).)*)</dl>", "$1"); RegexInfo cityRegexInfo2 = new RegexInfo("(<a href=\"[^\"]+\" onclick=\"co\\([^\"]+\">[^<>]+</a>)", "$1"); Dictionary <string, RegexInfo> cityRegexDic = new Dictionary <string, RegexInfo>(); cityRegexDic.Add("城市列表Text", cityRegexInfo); Dictionary <string, List <string> > dicCitylistText = SpiderHelp.GetHtmlByRegex("http://www.58.com/ershoufang/changecity/", "utf-8", cityRegexDic, WebsiteManager.GetWebById(WebsiteManager.五八同城_ID), CityId); string cityText = dicCitylistText["城市列表Text"].Count > 0 ? dicCitylistText["城市列表Text"][0] : ""; cityRegexDic.Add("城市列表", cityRegexInfo2); Dictionary <string, List <string> > dicCitylist = SpiderHelp.GetStrByRegex(cityText, cityRegexDic); List <string> cityList = dicCitylist["城市列表"]; StringBuilder citySb = new StringBuilder(); foreach (string cityInfoStr in cityList) { RegexInfo regexCityName = new RegexInfo("<a href=\"[^\"]+\" onclick=\"co\\([^\"]+\">([^<>]+)</a>", "$1"); RegexInfo regexCityUrl = new RegexInfo("<a href=\"([^\"]+)\" onclick=\"co\\([^\"]+\">[^<>]+</a>", "$1"); Dictionary <string, RegexInfo> cityRegexDic2 = new Dictionary <string, RegexInfo>(); cityRegexDic2.Add("regexCityName", regexCityName); cityRegexDic2.Add("regexCityUrl", regexCityUrl); Dictionary <string, List <string> > dicCityInfo = SpiderHelp.GetStrByRegex(cityInfoStr, cityRegexDic2); string cityName = StringHelp.TrimBlank(dicCityInfo["regexCityName"].Count > 0 ? dicCityInfo["regexCityName"][0] : ""); string cityUrl = dicCityInfo["regexCityUrl"].Count > 0 ? dicCityInfo["regexCityUrl"][0] : ""; string execStr = " exec 往网站爬取配置表添加配置信息 '{0}','{1}','{2}','{3}','{4}',{5},{6}"; 城市表 city = CityManager.Get城市_byLike城市名称(cityName); if (city != null && SpiderWebConfigManager.get网站爬取配置_by城市ID_网站ID(city.ID, WebsiteManager.五八同城_ID) == null) { execStr = string.Format(execStr, WebsiteManager.五八同城, city.城市名称, cityUrl.Replace("/ershoufang", ""), cityUrl.TrimEnd('/') + "/", "", "2000", "2000"); citySb.Append(execStr).Append("\r\n"); } } string result = citySb.ToString(); 导出任务计划配置文件(); }
private void method_0() { if (this.int_0 >= 0) { int int0 = this.int_0; this.textBox_1.Text = this.propertyInfo_0[int0].Name; if (this.propertyInfo_0[int0].PropertyType != typeof(RegexInfo)) { this.propertyInfo_0[int0].SetValue(this.ruleConfigInfo_0, this.textBox_0.Text, null); } else { RegexInfo regexInfo = new RegexInfo() { RegexName = this.textBox_1.Text, Method = this.comboBox_1.Text, Pattern = this.textBox_0.Text, FilterPattern = this.textBox_3.Text, Options = RegexOptions.None }; RegexInfo regexInfo1 = regexInfo; if (this.checkBox_0.Checked) { regexInfo1.Options = RegexOptions.IgnoreCase; } if (this.checkBox_1.Checked) { regexInfo1.Options = RegexOptions.Singleline; } if ((!this.checkBox_0.Checked ? false : this.checkBox_1.Checked)) { regexInfo1.Options = RegexOptions.IgnoreCase | RegexOptions.Singleline; } this.propertyInfo_0[int0].SetValue(this.ruleConfigInfo_0, regexInfo1, null); } } this.int_0 = this.listBox_0.SelectedIndex; }
private void changeFunc() { this.txtStatus.ForeColor = Color.Blue; this.txtStatus.Text = "修改信息:正在修改..."; Application.DoEvents(); RegexInfo myLoginInfo = new RegexInfo(); if (this.txtPasswd.Text != "" && this.txtChangeTo.Text != "") { if (this.txtPasswd.Text == this.txtChangeTo.Text) { if (myLoginInfo.isPasswdSecurity(this.txtChangeTo.Text)) { ManageDB myManageDB = new ManageDB(); myManageDB.UpdateDB("用户管理", "[passWord]", this.txtChangeTo); TimeDelay myTimeDelay = new TimeDelay(); this.btnOK.Enabled = false; this.btnCancel.Enabled = false; myTimeDelay.restartDelay(3, this.txtStatus, "修改信息:修改成功!", "请重新登录!"); } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "修改信息:修改失败!密码为含数字、字母6位以上字符!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "修改信息:修改失败,密码输入不一致!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "修改信息:修改失败,所有项不能为空!"; } }
private void buttonDelete_Click(object sender, EventArgs e) { List <RegexInfo> newList = new List <RegexInfo>(); IDictionary <Guid, Guid> toDelete = new Dictionary <Guid, Guid>(); foreach (var item in dataGridViewRegexs.SelectedItems) { RegexInfo regexInfo = item as RegexInfo; toDelete.Add(regexInfo.Id, regexInfo.Id); if (CurrentRegexInfo != null && regexInfo.Id == CurrentRegexInfo.Id) { SetCurrentRegexInfo(null, true, false); } } for (int i = 0; i < CurrentRegexs.Count; i++) { if (!toDelete.ContainsKey(CurrentRegexs[i].Id)) { newList.Add(CurrentRegexs[i]); } } model.SaveRegexs(newList); RefreshLoadedRegexsView(); }
public static string GetRegexInfoXmlByObj(RegexInfo obj, string name, string remark) { StringBuilder sb = new StringBuilder(); sb.Append("<regexinfo Name=\"").Append(name).Append("\" Remark=\"").Append(remark).Append("\"> "); sb.Append("<!--").Append(obj.RegexStr).Append("-->"); sb.Append("<regex>").Append(obj.RegexStr.EncodeField()).Append("</regex>"); sb.Append("<index>").Append(obj.RegexIndex).Append("</index>"); if (obj.RegexInfoList != null && obj.RegexInfoList.Count > 0) { sb.Append("<regexinfolist>"); foreach (RegexInfo _obj in obj.RegexInfoList) { sb.Append("<regexinfo>"); sb.Append("<!--").Append(_obj.RegexStr).Append("-->"); sb.Append("<regex>").Append(_obj.RegexStr.EncodeField()).Append("</regex>"); sb.Append("<index>").Append(_obj.RegexIndex).Append("</index>"); sb.Append("</regexinfo>"); } sb.Append("</regexinfolist>"); } sb.Append("</regexinfo>"); return(sb.ToString()); }
/// <summary> /// 根据正则表达式获取字符串 /// </summary> /// <param name="str">要监测的字符</param> /// <param name="regex">正则表达式</param> /// <param name="index">要获取符合正则的字符索引例如:$1</param> /// <returns></returns> public static List <string> GetStrByRegexByIndex(string str, RegexInfo regexInfo) { List <string> resultList = new List <string>(); if (regexInfo == null) { return(resultList); } string regex = regexInfo.RegexStr; if (string.IsNullOrEmpty(regex)) { return(resultList); } string index = regexInfo.RegexIndex; Regex r = new Regex(regex, RegexOptions.IgnoreCase); //定义一个Regex对象实例 MatchCollection mc = r.Matches(str); if (mc.Count > 0) { for (int i = 0; i < mc.Count; i++) { if (string.IsNullOrEmpty(index)) { resultList.Add(mc[i].Value); continue; } string result = ""; if (Regex.IsMatch(str, regex, RegexOptions.IgnoreCase)) { result = Regex.Replace(mc[i].Value, regex, index, RegexOptions.IgnoreCase); } resultList.Add(result); } } else if (regexInfo.RegexInfoList != null && regexInfo.RegexInfoList.Count > 0) { foreach (RegexInfo _regexInfo in regexInfo.RegexInfoList) { Regex _r = new Regex(_regexInfo.RegexStr, RegexOptions.IgnoreCase); //定义一个Regex对象实例 MatchCollection _mc = _r.Matches(str); if (_mc.Count > 0) { for (int i = 0; i < _mc.Count; i++) { if (string.IsNullOrEmpty(_regexInfo.RegexIndex)) { resultList.Add(_mc[i].Value); continue; } string result = ""; if (Regex.IsMatch(str, _regexInfo.RegexStr, RegexOptions.IgnoreCase)) { result = Regex.Replace(_mc[i].Value, _regexInfo.RegexStr, _regexInfo.RegexIndex, RegexOptions.IgnoreCase); } resultList.Add(result); } break; } } } return(resultList); }/// <summary>
public PathParameterMatcher(RegexInfo regexInfo) { _regexInfo = regexInfo ?? throw new ArgumentNullException(nameof(regexInfo)); }
private void btnOK_Click(object sender, EventArgs e) { if (this.stbFolderName.Text != "") { RegexInfo myLoginInfo = new RegexInfo(); if (myLoginInfo.isProjectName(this.stbFolderName.Text)) { if (MainForm.selectedNodePath != "") { folderLocation = MainForm.selectedNodePath + "\\" + this.stbFolderName.Text; DirectoryInfo myDirInfo = new DirectoryInfo(MainForm.selectedNodePath); DirectoryInfo [] chldFolders = myDirInfo.GetDirectories(); foreach (DirectoryInfo chldFolder in chldFolders) { newFolderNameList.Add(chldFolder.Name); newFolderName = newFolderNameList.ToArray(); } if (newFolderName != null) { if (Array.IndexOf <string>(newFolderName, this.stbFolderName.Text) != -1) { MessageBox.Show("文件夹名称冲突,请修改工程名称!", "消息提示:", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.IsCreateFolder = true; createFolder(folderLocation); this.txtStatus.ForeColor = Color.Green; this.txtStatus.Text = "创建信息:创建成功!"; this.Close(); this.DialogResult = DialogResult.OK; } } else { this.IsCreateFolder = true; createFolder(folderLocation); this.txtStatus.ForeColor = Color.Green; this.txtStatus.Text = "创建信息:创建成功!"; this.Close(); this.DialogResult = DialogResult.OK; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,所选项目为空!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,请正确填写文件夹名称!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "创建信息:创建失败,文件夹名称不能为空!"; } }
public string MDFA1(RegexInfo reg, string strText) { System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(0); return(getFormula1PropertyString(sf.GetMethod().Name)); }
public void Run() { //ip列表页ip信息 RegexInfo regex_ipInfo = new RegexInfo("([^<>]+\\@[^<>]+</font>)", "$1"); //ip列表页ip RegexInfo regex_ip = new RegexInfo("([^<>]+)\\@[^<>]+</font>", "$1"); //ip列表页ip区域 RegexInfo regex_area = new RegexInfo("[^<>]+\\#([^<>]+)</font>", "$1"); Dictionary <string, RegexInfo> regexDic1 = new Dictionary <string, RegexInfo>(); regexDic1.Add("regex_ipInfo", regex_ipInfo); Dictionary <string, RegexInfo> regexDic2 = new Dictionary <string, RegexInfo>(); regexDic2.Add("regex_ip", regex_ip); regexDic2.Add("regex_area", regex_area); //从文本文件中获取爬取ip分类页面列表 List <string> urlList = new List <string>(); string configPath = AppDomain.CurrentDomain.BaseDirectory + "IP代理/Config/Lastro网IP代理ProxyIpConfig.txt"; StreamReader sr = new StreamReader(configPath); while (true) { string str = sr.ReadLine(); if (str == null) { break; } else { urlList.Add(str); } } sr.Close(); sr.Dispose(); //但从当前页面中获取爬取ip分类列表 RegexInfo regex_urllist = new RegexInfo("<a href=\"([^\"]+)\"[^<>]*>【国内代理】[^<>]+</a>", "$1"); RegexInfo regex_urllist_pagecount = new RegexInfo("<span title=\"共[^\"]+页\"> /([^<>]+)页", "$1"); Dictionary <string, RegexInfo> regexDic3 = new Dictionary <string, RegexInfo>(); regexDic3.Add("regex_urllist", regex_urllist); regexDic3.Add("regex_urllist_pagecount", regex_urllist_pagecount); int urllist_index = 1; int urllist_max_index = 1; string urllist_nextPage_para = "http://www.httpip.net/forum-36-{0}.html"; //下一页 string urllist_nextPage = string.Format(urllist_nextPage_para, urllist_index); //下一页 try { begin_nextpage: Dictionary <string, List <string> > dicValueList3 = SpiderHelp.GetHtmlByRegexNotProxyIp(urllist_nextPage, "gb2312", regexDic3); List <string> urlList2 = dicValueList3["regex_urllist"];//所有ip列表集合 urlList.AddRange(urlList2); urllist_max_index = dicValueList3["regex_urllist_pagecount"].Count < 1 ? 0 : Convert.ToInt32(dicValueList3["regex_urllist_pagecount"][0].TrimBlank()); if (urllist_index < urllist_max_index) { urllist_index = urllist_index + 1; urllist_nextPage = string.Format(urllist_nextPage_para, urllist_index); } else { urllist_nextPage = ""; } //开始爬取当前页列表ip页面 SysData_ProxyIp existsObj = new SysData_ProxyIp(); string message = ""; for (int i = 0; i < urlList.Count(); i++) { string urlInfo = urlList[i]; string url = urlInfo.Split('$')[0]; string urlHost = urlInfo.Split('$').Length < 2 ? "http://www.httpip.net/" : urlInfo.Split('$')[1]; requestpage: if (!url.ToLower().Contains("http://")) { url = urlHost + url; } Dictionary <string, List <string> > dicValueList = SpiderHelp.GetHtmlByRegexNotProxyIp(url, "gb2312", regexDic1); List <string> ipInfoList = dicValueList["regex_ipInfo"]; //所有ip集合 string nextPage = ""; //下一页链接 if (ipInfoList == null || ipInfoList.Count < 1) { log.Debug(string.Format("未获取到IP列表,url:{0}", url)); continue; } foreach (string ipInfo in ipInfoList) { Dictionary <string, List <string> > infoListDic = SpiderHelp.GetStrByRegex(ipInfo, regexDic2); string ip = infoListDic["regex_ip"].Count < 1 ? "" : infoListDic["regex_ip"][0]; string ipArea = infoListDic["regex_area"].Count < 1 ? "" : infoListDic["regex_area"][0]; ip = ip.TrimBlank(); int result = ProxyIpHelp.ImportProxyIp(ip, ipArea, out existsObj, out message); if (result != 1) { log.Debug(string.Format("{0},url:{1},ip:{2}", message, url, ip == null ? "null" : ip)); continue; } else { log.Debug(string.Format("ip插入成功,url:{0},ip:{1}", url, ip == null ? "null" : ip)); } } if (!string.IsNullOrEmpty(nextPage)) { if (!nextPage.ToLower().Contains("http://")) { url = urlHost + nextPage; } goto requestpage; } } if (!string.IsNullOrEmpty(urllist_nextPage)) { urlList = new List <string>(); goto begin_nextpage; } } catch (Exception ex) { log.Error("系统异常", ex); } }
public void Run() { //ip列表页ip信息 RegexInfo regex_ipInfo = new RegexInfo("(\\ \\;[^<>]+<br />)", "$1"); //ip列表页ip RegexInfo regex_ip = new RegexInfo("\\ \\;([^<>\\s]+) ([^<>\\s]+) [^<>]+<br />", "$1:$2"); //ip列表页ip区域 RegexInfo regex_area = new RegexInfo("\\ \\;[^<>\\s]+ [^<>\\s]+ ([^<>\\s]+) [^<>]+<br />", "$1"); Dictionary <string, RegexInfo> regexDic1 = new Dictionary <string, RegexInfo>(); regexDic1.Add("regex_ipInfo", regex_ipInfo); Dictionary <string, RegexInfo> regexDic2 = new Dictionary <string, RegexInfo>(); regexDic2.Add("regex_ip", regex_ip); regexDic2.Add("regex_area", regex_area); //从文本文件中获取爬取ip分类页面列表 List <string> urlList = new List <string>(); string configPath = AppDomain.CurrentDomain.BaseDirectory + "IP代理/Config/猫扑网IP代理ProxyIpConfig.txt"; StreamReader sr = new StreamReader(configPath); while (true) { string str = sr.ReadLine(); if (str == null) { break; } else { urlList.Add(str); } } sr.Close(); sr.Dispose(); //但从当前页面中获取爬取ip分类列表 RegexInfo regex_urllist = new RegexInfo("<DT><a href=\"([^\"]+)\" target=\"_blank\">[^<>]+</a></DT>", "$1"); RegexInfo regex_urllist_pagecount = new RegexInfo("<a href=\"http://www.itmop.com/proxy/catalog.asp\\?page=(\\d+)\">\\»\\;</a></DIV>", "$1"); Dictionary <string, RegexInfo> regexDic3 = new Dictionary <string, RegexInfo>(); regexDic3.Add("regex_urllist", regex_urllist); regexDic3.Add("regex_urllist_pagecount", regex_urllist_pagecount); int urllist_index = 1; int urllist_max_index = 1; string urllist_nextPage_para = "http://www.itmop.com/proxy/catalog.asp?page={0}"; //下一页 string urllist_nextPage = string.Format(urllist_nextPage_para, urllist_index); //下一页 try { begin_nextpage: //获取ip列表页url Dictionary <string, List <string> > dicValueList3 = SpiderHelp.GetHtmlByRegexNotProxyIp(urllist_nextPage, "utf-8", regexDic3); List <string> urlList2 = dicValueList3["regex_urllist"];//所有ip列表集合 urlList.AddRange(urlList2); //获取ip列表列表页的最大页数 urllist_max_index = dicValueList3["regex_urllist_pagecount"].Count < 1 ? 0 : Convert.ToInt32(dicValueList3["regex_urllist_pagecount"][0].TrimBlank()); if (urllist_index < urllist_max_index) { urllist_index = urllist_index + 1; urllist_nextPage = string.Format(urllist_nextPage_para, urllist_index); } else { urllist_nextPage = ""; } //开始爬取当前页列表ip页面 SysData_ProxyIp existsObj = new SysData_ProxyIp(); string message = ""; for (int i = 0; i < urlList.Count(); i++) { string urlInfo = urlList[i]; urlInfo = urlInfo.Replace("&", "&"); string url = urlInfo.Split('$')[0]; string urlHost = urlInfo.Split('$').Length < 2 ? "http://www.itmop.com" : urlInfo.Split('$')[1]; requestpage: //根据ip列表页url爬取ip信息 if (!url.ToLower().Contains("http://")) { url = urlHost + url; } Dictionary <string, List <string> > dicValueList = SpiderHelp.GetHtmlByRegexNotProxyIp(url, "utf-8", regexDic1); List <string> ipInfoList = dicValueList["regex_ipInfo"];//所有ip集合 string nextPage = ""; if (ipInfoList == null || ipInfoList.Count < 1) { log.Debug(string.Format("未获取到IP列表,url:{0}", url)); continue; } foreach (string ipInfo in ipInfoList) { Dictionary <string, List <string> > infoListDic = SpiderHelp.GetStrByRegex(ipInfo, regexDic2); string ip = infoListDic["regex_ip"].Count < 1 ? "" : infoListDic["regex_ip"][0]; string ipArea = infoListDic["regex_area"].Count < 1 ? "" : infoListDic["regex_area"][0]; ipArea = ipArea.RemoveHeml(); ip = ip.TrimBlank(); int result = ProxyIpHelp.ImportProxyIp(ip, ipArea, out existsObj, out message); if (result != 1) { log.Debug(string.Format("{0},url:{1},ip:{2}", message, url, ip == null ? "null" : ip)); continue; } else { log.Debug(string.Format("ip插入成功,url:{0},ip:{1}", url, ip == null ? "null" : ip)); } } if (!string.IsNullOrEmpty(nextPage)) { url = urlHost + nextPage; goto requestpage; } } if (!string.IsNullOrEmpty(urllist_nextPage)) { urlList = new List <string>(); goto begin_nextpage; } } catch (Exception ex) { log.Error("系统异常", ex); } }
protected override Regex Revert(RegexInfo value) { return(new Regex(value.Pattern, value.Options)); }
public void start() { RegexInfo 项目JSON信息正则 = new RegexInfo("(\\{[^\\}]*\\})", "$1"); RegexInfo 项目ID正则 = new RegexInfo("'PARENTPROJID':'([^']*)'", "$1"); RegexInfo 项目行政区正则 = new RegexInfo("'F_SITE':'([^']*)'", "$1"); RegexInfo 楼栋JSON信息正则 = new RegexInfo("(\\{[^\\}]*\\})", "$1"); RegexInfo 楼栋ID正则 = new RegexInfo("'BUILDID':'([^']*)'", "$1"); RegexInfo 楼栋名称正则 = new RegexInfo("'F_BLOCK':'([^']*)'", "$1"); RegexInfo 楼盘名项目名正则 = new RegexInfo("\"projectName\":\"([^\"]*)\"", "$1"); RegexInfo 坐落地址正则 = new RegexInfo("\"location\":\"([^\"]*)\"", "$1"); Dictionary <string, RegexInfo> 正则集合字典 = new Dictionary <string, RegexInfo>(); 正则集合字典.Add("项目JSON信息", 项目JSON信息正则); Dictionary <string, RegexInfo> 正则集合字典_楼栋内页 = new Dictionary <string, RegexInfo>(); 正则集合字典_楼栋内页.Add("楼盘名项目名", 楼盘名项目名正则); 正则集合字典_楼栋内页.Add("坐落地址", 坐落地址正则); string NowEncoding = "utf-8"; string 项目列表页URL分页参数 = "http://www.cq315house.com/315web/webservice/GetMyData913.ashx?projectname=&kfs=&projectaddr=&pagesize=10&pageindex={0}&presalecert="; string 项目详细页URL参数 = "http://www.cq315house.com/315web/webservice/GetMyData112.ashx?projectId={0}&type=1"; string 楼栋详细页面URL参数 = "http://www.cq315house.com/315web/HtmlPage/ShowRooms.htm?block={0}&buildingid={1}"; string 楼栋详细页面URL参数1 = "http://www.cq315house.com/315web/webservice/GetBuildingInfo.ashx?buildingId={0}"; string 楼盘名 = ""; // string 所属县区 = ""; // string 地址 = ""; // string 预售许可证号_房产证号 = ""; string 楼栋编号 = ""; string 单元 = ""; //unitnumber: string 义层 = ""; //flr: string 房号 = ""; //flr:+x: string 跃式 = ""; //rn: string 套内面积 = ""; //iArea: string 建筑面积 = ""; //bArea: string 使用用途 = ""; //use: string 户型 = ""; //rType: string 拟售单价_套内 = ""; //nsjg: string 拟售单价_建面 = ""; //nsjmjg: string 建筑结构 = ""; //stru string 签约状况 = ""; //F_ISONLINESIGN:(0:未签约) string 房屋状态 = ""; //F_ISOWNERSHIP:(0:可售) for (long i = 1; i > 0; i++) { //**********项目列表页信息(获取项目链接)************// Dictionary <string, List <string> > 项目列表页结果 = SpiderHelp.GetHtmlByRegex( string.Format(项目列表页URL分页参数, i), "utf-8", 正则集合字典, null, 0); List <string> 项目JSON信息List = 项目列表页结果["项目JSON信息"]; foreach (string 项目json in 项目JSON信息List) { List <string> 项目IDList = SpiderHelp.GetStrByRegexByIndex(项目json, 项目ID正则); List <string> 项目行政区List = SpiderHelp.GetStrByRegexByIndex(项目json, 项目行政区正则); string 项目ID = 项目IDList.Count > 0 ? 项目IDList[0] : ""; 所属县区 = 项目行政区List.Count > 0 ? 项目行政区List[0] : ""; //*************项目详细页面信息(获取楼栋链接)*************// 正则集合字典.Add("楼栋JSON信息", 楼栋JSON信息正则); string 项目详细URL = string.Format(项目详细页URL参数, 项目ID); Dictionary <string, List <string> > 楼栋列表页结果 = SpiderHelp.GetHtmlByRegex( 项目详细URL, "utf-8", 正则集合字典, null, 0); List <string> 楼栋JSON信息List = 楼栋列表页结果["楼栋JSON信息"]; foreach (string 楼栋json in 楼栋JSON信息List) { List <重庆_楼栋> 楼栋链接信息 = new List <重庆_楼栋>(); List <string> 楼栋IDList = SpiderHelp.GetStrByRegexByIndex(楼栋json, 楼栋ID正则); List <string> 楼栋名称List = SpiderHelp.GetStrByRegexByIndex(楼栋json, 楼栋名称正则); string 楼栋ID = 楼栋IDList.Count > 0 ? 楼栋IDList[0] : ""; string 楼栋名称 = 楼栋名称List.Count > 0 ? 楼栋名称List[0] : ""; if (!string.IsNullOrEmpty(楼栋ID) && !string.IsNullOrEmpty(楼栋名称)) { string[] 楼栋ID数组 = 楼栋ID.Split(','); string[] 楼栋名称数组 = 楼栋名称.Split(','); for (int j = 0; j < 楼栋ID数组.Length; j++) { if (j >= 楼栋名称数组.Length) { break; } if (!string.IsNullOrEmpty(楼栋ID数组[j])) { 重庆_楼栋 obj = new 重庆_楼栋(); obj.楼栋名称 = 楼栋名称数组[j]; obj.楼栋ID = 楼栋ID数组[j]; 楼栋链接信息.Add(obj); } } } foreach (重庆_楼栋 楼栋obj in 楼栋链接信息) { //*************楼栋详细页面信息(获取房号信息)*************// string 楼栋URL = string.Format(楼栋详细页面URL参数1, 楼栋obj.楼栋ID); Dictionary <string, List <string> > 楼栋内页信息List = SpiderHelp.GetHtmlByRegex(楼栋URL, "utf-8", 正则集合字典_楼栋内页, null, 0); 楼盘名 = 楼栋内页信息List["楼盘名项目名"].Count > 0 ? 楼栋内页信息List["楼盘名项目名"][0] : ""; 地址 = 楼栋内页信息List["坐落地址"].Count > 0 ? 楼栋内页信息List["坐落地址"][0] : ""; } } } } }
public ComicSource(string name, string urlFormat, string?minDate, string?maxDate, bool isHtml, RegexInfo regex) { this.name = name; this.urlFormat = urlFormat; if (minDate is string f**k) { this.minDate = DateTime.Parse(f**k); } if (maxDate is string fuckdos) { this.maxDate = DateTime.Parse(fuckdos); } this.isHtml = isHtml; this.regex = regex; }
static SpiderHelp() { regex_checkcode = regex_ganji_checkcode; regex_checkcode.RegexInfoList.Add(regex_58_checkcode); }
private void myRegisterFunc() { ManageDB myManageDB = new ManageDB(); RegexInfo myLoginInfo = new RegexInfo(); this.txtStatus.ForeColor = Color.Blue; this.txtStatus.Text = "注册信息:注册中..."; Application.DoEvents(); if (this.txtUserName.Text != "" && this.txtPasswd.Text != "" && this.txtConfirmPassWD.Text != "" & txtEmailAddress.Text != "" && this.txtUserFullName.Text != "") { if (myLoginInfo.isUserNameFair(this.txtUserName.Text)) { if (!myManageDB.checkUserNameDuplicate(this.txtUserName.Text)) { if (this.txtPasswd.Text == this.txtConfirmPassWD.Text) { if (myLoginInfo.isPasswdSecurity(this.txtPasswd.Text)) { if (myLoginInfo.isMailAddress(this.txtEmailAddress.Text)) { userName = this.txtUserName.Text; passwd = this.txtPasswd.Text; fullName = this.txtUserFullName.Text; emailAddress = this.txtEmailAddress.Text; verificationReg(); this.Visible = false; this.Close(); UserAuthentication myAuthentication = new UserAuthentication(); myAuthentication.Show(); } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败,请正确填写邮箱格式!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败!密码为含数字、字母6-20位以上字符!"; } } else if (myManageDB.checkUserNameDuplicate(this.txtUserName.Text)) { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败,密码不一致!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败,用户名已存在!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败,用户名为含数字、字母的6-20位字符!"; } } else { this.txtStatus.ForeColor = Color.Red; this.txtStatus.Text = "注册信息:注册失败,所有项均不能为空!"; } }