예제 #1
0
        public void GetVideoList()
        {
            if (!start)
            {
                return;
            }
            try
            {
                HtmlDelegate PageData  = new HtmlDelegate(GetHtml);
                IAsyncResult PageAsync = PageData.BeginInvoke("http://www.mp4ba.com/index.php?page=" + (moviepage++).ToString(), AsyncPages, null);

                //return;
                //string InfoBody = "";
                //string ret = GetHtml("http://www.mp4ba.com/index.php?page=" + (moviepage++).ToString());
                //Regex pattern = new Regex(@"data_list""\>([\w\W]+?)\<\/tbody");
                //Match matchMode = pattern.Match(ret);//匹配整个信息段
                //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)
                //    {
                //        HtmlDelegate HtmlData = new HtmlDelegate(GetHtml);
                //        IAsyncResult async = HtmlData.BeginInvoke("http://www.mp4ba.com/" + matchMode.Groups[1].Value, TestCallback, null);
                //    }
                //    else
                //    {
                //        Logs("匹配内容链接", -1, "匹配内容链接失败", item.Groups[1].Value);
                //    }

                //}
            }
            catch (Exception e)
            {
                Logs("获取电影列表", -1, "处理错误 " + e.Message, moviepage.ToString());
            }
        }//从mp4ba上获取电影列表
예제 #2
0
        }  //异步响应函数

        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());
            }
        }  //异步响应函数