public static int GetBoardPageCountPro(string sourceHtml) { string regexString = "(<div\\s+class=\"pages\".*?>([<.*?>]*)</div>)"; string result = RegexUtility.GetMatch(sourceHtml, regexString).Replace("</a>", "</a>|").Replace("<a", "|<a"); string nums = Web.Utils.RemoveHtml(result); MatchCollection mc = RegexUtility.GetMatchFull(nums, "[0-9]+"); string pageString = string.Empty; if (mc.Count > 0) { pageString = mc[mc.Count - 1].Groups[0].Value; } int pageCount; if (int.TryParse(pageString, out pageCount)) { return(pageCount); } else { return(-1); } }
public static MatchCollection GetThreadsInBoard(string sourceHtml) { string regexstring = RegexStringLib.GetThreadsInBoard(); MatchCollection mc = RegexUtility.GetMatchFull(sourceHtml, regexstring); return(mc); }
void _httper_RequestStringCompleted(object sender, RequestStringCompletedEventArgs e) { this._CompletedCount++; if (e.Error == null) { System.Text.RegularExpressions.MatchCollection mc = RegexUtility.GetMatchFull(e.ResponseString, ((ProxySourcePageInfo)e.UserState).RegexString); if (mc != null) { foreach (System.Text.RegularExpressions.Match m in mc) { ProxyInfo info = new ProxyInfo(); info.Name = ""; info.Address = m.Groups[1].Value.Split(':')[0]; info.Port = Convert.ToInt32(m.Groups[1].Value.Split(':')[1]); SendStatusChanged(string.Format("取得:{0}:{1}", info.Address, info.Port), ""); this._ProxyList.Add(info); } } } else { #warning todo error } if (this._CompletedCount == this._SourcePageInfo.Count) { if (this.Completed != null) { this.Completed(this, new Natsuhime.Events.ReturnCompletedEventArgs(this._ProxyList, null, false, "77777")); } } }
void httper_RequestStringCompleted(object sender, RequestStringCompletedEventArgs e) { if (e.Error == null) { if (e.ResponseString != string.Empty) { if (e.UserState.ToString() == "GETLIST") { #region 获取列表 #region 正则 MatchCollection mc = RegexUtility.GetMatchFull(e.ResponseString, tbxPreListRegex.Text.Trim(), RegexOptions.Singleline | RegexOptions.IgnoreCase); if (mc != null) { foreach (Match m in mc) { WebContentListInfo wcli = new WebContentListInfo(); wcli.Title = m.Groups[1].Value.Trim(); wcli.ContentList = new List <WebContentInfo>(); MatchCollection mcContent = RegexUtility.GetMatchFull(m.Groups[2].Value, tbxListRegex.Text.Trim()); if (mcContent != null) { foreach (Match mContent in mcContent) { WebContentInfo wci = new WebContentInfo(); wci.Title = mContent.Groups[2].Value.Trim(); wci.Url = mContent.Groups[1].Value.Trim(); wcli.ContentList.Add(wci); } WebContentLists.Add(wcli); } } } #endregion #region 显示 this.lvList.Items.Clear(); foreach (WebContentInfo info in WebContentLists[0].ContentList) { ListViewItem lv = new ListViewItem(info.Title); ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(lv, info.Url); ListViewItem.ListViewSubItem lvsi2 = new ListViewItem.ListViewSubItem(lv, info.Title); lv.SubItems.Add(lvsi); lv.SubItems.Add(lvsi2); this.lvList.Items.Add(lv); } MessageBox.Show(this, string.Format("{0}章完成!", WebContentLists.Count)); this.btnGetList.Enabled = true; #endregion } #endregion } else { #region 获取内容 WebContentInfo wci = (WebContentInfo)e.UserState; string content = RegexUtility.ReplaceRegex( tbxPreContentRegex.Text.Trim(), e.ResponseString, "", RegexOptions.Singleline | RegexOptions.IgnoreCase ); MatchCollection mc = RegexUtility.GetMatchFull( content, tbxContentRegex.Text.Trim(), RegexOptions.Singleline | RegexOptions.IgnoreCase ); if (mc != null) { StringBuilder sb = new StringBuilder(); sb.Append(wci.Title + Environment.NewLine); foreach (Match m in mc) { if (m.Groups[1].Value.IndexOf("盗墓笔记网友留言") < 0) { sb.Append(m.Groups[1].Value + Environment.NewLine); } } sb.Append(Environment.NewLine); sb.Append(Environment.NewLine); string savepath = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "down" ); if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } try { FileStream fs = new FileStream( Path.Combine(savepath, this.WebContentLists[0].Title + ".txt"), FileMode.Append ); StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true, true)); sw.Write(Natsuhime.Web.Utils.RemoveHtml(sb.ToString())); sw.Flush(); sw.Close(); fs.Close(); this.WebContentLists[0].ContentList.Remove(wci); DownNextContent(); } catch (Exception ex) { this.btnGetContent.Enabled = true; } } #endregion } } else { MessageBox.Show("返回空"); } } else { MessageBox.Show(e.Error.Message); } }