教育网的5Q网站有很多的资源,其中包括很多讲座学习资料,天天上觉得不方便,于是写了一个小软件来解析它。加入XtraGrid控件,查看方便,希望大家多给意见! waxwork3@163.com 正则解析源码: try { this.m_WaitDialogForm.Caption = "Geting page"; this.GetPage(); this.m_WaitDialogForm.Caption = "Parsing data"; string regex = @"(?<PublishTime>\d\d-\d\d\s\d\d:\d\d) .*\n.*0066CC> (?<Catalog>[^<]*) .*\n.*red> (?<Seed>[^<]*) .*\n.*green> (?<Connection>[^<]*) .*\n.*?"" (?<SeedLink>[^""]*) .*? (?<Content>【.*?) </.*\n.*?"" (?<Seed_1>[^""]*) "".*?"" (?<Seed_2>[^""]*) "".*?"" (?<Seed_3>[^""]*) "".*?"" (?<Detail>[^""]*) .*\n.*> (?<Capacity>.*\..*?) <.*\n.*> (?<Completed> .*)< "; System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options); Match MatchResults = reg.Match(this.m_SubjectString); while (MatchResults.Success) { DataRow drw = this.m_dsBT.BT.Rows.Find(MatchResults.Groups["Content"].Value.GetHashCode()); if(drw != null) { drw["Seed"] = Convert.ToInt32(MatchResults.Groups["Seed"].ToString()); drw["Connection"] = Convert.ToInt32(MatchResults.Groups["Connection"].ToString());; MatchResults = MatchResults.NextMatch(); continue; } dsBT.BTRow row = tbl.NewBTRow(); try { row.BeginEdit(); row.Content = MatchResults.Groups["Content"].ToString(); row.ContentHashCode = MatchResults.Groups["Content"].Value.GetHashCode(); row.PublishTime = Convert.ToDateTime(DateTime.Now.Year + "-" + MatchResults.Groups["PublishTime"].ToString()); row.Catalog = MatchResults.Groups["Catalog"].ToString(); row.Seed = Convert.ToInt32(MatchResults.Groups["Seed"].ToString()); row.Connection = Convert.ToInt32(MatchResults.Groups["Connection"].ToString()); row.SeedLink = MatchResults.Groups["SeedLink"].ToString(); row.Detail = MatchResults.Groups["Detail"].ToString(); row.Completed = Convert.ToInt32(MatchResults.Groups["Completed"].ToString()); row.History = 0; strTemp = MatchResults.Groups["Capacity"].ToString(); if(strTemp.IndexOf("M") - 1 > 0) { strTemp = strTemp.Substring(0, strTemp.Length - 3 > 0 ? strTemp.Length - 3 : 0); row.Capacity = (int)Convert.ToSingle(strTemp); } else { strTemp = strTemp.Substring(0, strTemp.Length - 3 > 0 ? strTemp.Length - 3 : 0); row.Capacity = (int)(Convert.ToSingle(strTemp) * 1024); } row.EndEdit(); tbl.Rows.Add(row); } catch(Exception ex) { this.comboBox1.SelectedIndex = this.comboBox1.SelectedIndex < 4 ? this.comboBox1.SelectedIndex + 1 : 0; frmMessage message = new frmMessage(ex.Message); message.Show(); // MessageBox.Show(ex.Message); } MatchResults = MatchResults.NextMatch(); } if(tbl.Rows.Count > 0) { foreach(DataRow row in this.m_dsBT.BT.Rows) { row["History"] = (int)row["History"] + 1; } this.Text = "上次更新时间:" + DateTime.Now.ToString() + " | 导入" + tbl.Rows.Count + "条数据"; this.m_WaitDialogForm.Close(); this.m_dsBT.Merge(tbl); this.gridView1.BestFitColumns(); } else { this.Text = "上次更新时间:" + DateTime.Now.ToString(); this.m_WaitDialogForm.Close(); } } catch (Exception ex) { this.comboBox1.SelectedIndex = this.comboBox1.SelectedIndex < 4 ? this.comboBox1.SelectedIndex + 1 : 0; this.m_WaitDialogForm.Close(); frmMessage message = new frmMessage(ex.Message); message.Show(); // MessageBox.Show(ex.Message); } 程序下载 转载于:https://www.cnblogs.com/waxwork3/archive/2006/02/24/336649.html