} //异步响应函数 public void AsyncPages(IAsyncResult data) { try { AsyncResult ar = (AsyncResult)data; HtmlDelegate del = (HtmlDelegate)ar.AsyncDelegate; string res = del.EndInvoke(ar); string InfoBody = ""; Regex pattern = new Regex(@"data_list""\>([\w\W]+?)\<\/tbody"); Match matchMode = pattern.Match(res);//匹配整个信息段 if (matchMode.Success) { InfoBody = matchMode.Groups[1].Value; } pattern = new Regex(@"tr class=""alt\d""\>([\w\W]+?)\<\/tr"); MatchCollection matchsMade = pattern.Matches(InfoBody);//匹配每条数据 foreach (Match item in matchsMade) { pattern = new Regex(@"href=""(show[\w\W]+?)"""); matchMode = pattern.Match(item.Groups[1].Value); //内容页链接 if (matchMode.Success) { SqlConnection sqlCnt = new SqlConnection(connectString); sqlCnt.Open(); DataSet myDataSet2 = new DataSet(); DataTable myTable2 = myDataSet2.Tables["Mp4baData"]; SqlDataAdapter myDataAdapter2 = new SqlDataAdapter("SELECT * FROM Mp4baData where DetailUrl = '" + "http://www.mp4ba.com/" + matchMode.Groups[1].Value + "'", sqlCnt); myDataAdapter2.Fill(myDataSet2, "Mp4baData"); myTable2 = myDataSet2.Tables["Mp4baData"]; if (myTable2.Rows.Count == 0) { HtmlDelegate HtmlData = new HtmlDelegate(GetHtml); IAsyncResult async = HtmlData.BeginInvoke("http://www.mp4ba.com/" + matchMode.Groups[1].Value, TestCallback, null); } else { listBox1.Items.Add(matchMode.Groups[1].Value + "已保存过..."); if (oldnum-- < 0) { start = false; listBox1.Items.Add("********************已完成更新*********************"); } sqlCnt.Close(); sqlCnt.Dispose(); // 释放数据库连接对象 } } else { Logs("匹配内容链接", -1, "匹配内容链接失败", item.Groups[1].Value); } } if (moviepage <= maxpage) { GetVideoList(); } listBox1.Items.Add("******" + (moviepage - 1) + "页 已完成******"); } catch (Exception e) { Logs("异步处理函数", -1, "列表解析错误" + e.Message, moviepage.ToString()); } } //异步响应函数
public void TestCallback(IAsyncResult data) { try { AsyncResult ar = (AsyncResult)data; HtmlDelegate del = (HtmlDelegate)ar.AsyncDelegate; string res = del.EndInvoke(ar); if (res == null || res == "") { Logs("异步处理函数", -1, "详细信息页面返回为空"); } string posttime = "", name = "", type = "", size = "", detailurl = "", introduction = "", seedurl = "", magneturl = ""; int snum = -1, dnum = -1, fnum = -1, urlhealth = -1; Regex pattern = new Regex(@"<p>发布时间: ([\w\W]+?)</p>"); Match matchMode = pattern.Match(res);//匹配大小 posttime = matchMode.Groups[1].Value; // <a href="index.php\?sort_id=5">([\w\W]+?)</a>([\w\W]+?)</div> pattern = new Regex(@"<div class=""location"">[\w\W]+?<a href=""index.php\?sort_id=[\w\W]*?"">([\w\W]+?)</a>([\w\W]+?)</div>"); matchMode = pattern.Match(res); //内容页链接 name = matchMode.Groups[2].Value.Replace("»", "").Replace(" ", ""); type = matchMode.Groups[1].Value; pattern = new Regex(@"<p>分享情况: 做种 ([\w\W]+?), 下载 ([\w\W]+?), 完成 ([\w\W]+?)</p>"); matchMode = pattern.Match(res); //内容页链接 try { snum = Convert.ToInt32(matchMode.Groups[1].Value); dnum = Convert.ToInt32(matchMode.Groups[2].Value); fnum = Convert.ToInt32(matchMode.Groups[3].Value); } catch { } pattern = new Regex(@"文件总大小:([\w\W]+?)</span>"); matchMode = pattern.Match(res); size = matchMode.Groups[1].Value; pattern = new Regex(@"magnet:\?xt=urn:btih:([\w\W]+?)&tr="); matchMode = pattern.Match(res); detailurl = "http://www.mp4ba.com/show.php?hash=" + matchMode.Groups[1].Value; Regex DPattern = new Regex(@"magnet"" href=""([\w\W]+?)"""); Match DMatch = DPattern.Match(res); if (DMatch.Success) { magneturl = DMatch.Groups[1].Value; } DPattern = new Regex(@"download"" href=""([\w\W]+?)"""); DMatch = DPattern.Match(res); if (DMatch.Success) { seedurl = DMatch.Groups[1].Value; } DPattern = new Regex(@"<img src=""images/health/([\w\W]+?).png"); DMatch = DPattern.Match(res); if (DMatch.Success) { try { urlhealth = Convert.ToInt32(DMatch.Groups[1].Value); } catch { } } DPattern = new Regex(@"(<div class=""intro"">[\w\W]+?)<div class=""clear"""); DMatch = DPattern.Match(res); if (DMatch.Success) { introduction = DMatch.Groups[1].Value; } if (name != "" && type != "") { WriteData(posttime, type, name, size, snum, dnum, fnum, detailurl, introduction, seedurl, magneturl, urlhealth); listBox1.Items.Add(name + " 已完成 " + posttime); } else { Logs("解析异常", -1, "关键字解析异常...in " + detailurl, res); listBox1.Items.Add(res + " 解析异常 " + posttime); } } catch (Exception e) { Logs("异步处理函数", -1, "关键字匹配错误" + e.Message, moviepage.ToString()); } } //异步响应函数