Ejemplo n.º 1
0
 /// <summary>
 /// 处理优化所填配置
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 private Code.CatchConfig HandleConfig(Code.CatchConfig config)
 {
     if (config.ListXPath != "")
     {
         config.ListXPath = config.ListXPath.Replace("\"", "").Replace("'", "");
         var tmp = config.ListXPath.Split('=');
         config.ListXPath = string.Format("//div[@{0}='{1}']|//td[@{0}='{1}']|//table[@{0}='{1}']", tmp[0], tmp[1]);
     }
     if (config.ItemXPath != "")
     {
         config.ItemXPath = config.ItemXPath.Replace("\"", "").Replace("'", "");
         var tmp = config.ItemXPath.Split('=');
         config.ItemXPath = string.Format("descendant::div[@{0}='{1}']|descendant::li[@{0}='{1}']|descendant::tr[@{0}='{1}']", tmp[0], tmp[1]);
     }
     if (config.TitleXPath != "")
     {
         config.TitleXPath = config.TitleXPath.Replace("\"", "").Replace("'", "");
         var tmp = config.TitleXPath.Split('=');
         config.TitleXPath = string.Format("descendant::div[@{0}='{1}']|descendant::td[@{0}='{1}']|descendant::span[@{0}='{1}']", tmp[0], tmp[1]);
     }
     if (config.PagingXPath != "")
     {
         config.PagingXPath = config.PagingXPath.Replace("\"", "").Replace("'", "");
         var tmp = config.PagingXPath.Split('=');
         config.PagingXPath = string.Format("//div[@{0}='{1}']|//td[@{0}='{1}']|//span[@{0}='{1}']", tmp[0], tmp[1]);
     }
     return(config);
 }
Ejemplo n.º 2
0
        private void btnComp_Click(object sender, EventArgs e)
        {
            string strUrl          = tbUrl.Text.Trim();
            string strContent      = tbContent.Text.Trim();
            string strListXPath    = tbListXPath.Text.Trim();
            string strItemXPath    = tbItemXPath.Text.Trim();
            string strTitleXPath   = tbTitleXPath.Text.Trim();
            string strPagingXPath  = tbPagingXPath.Text.Trim();
            string strPassStatus   = tbPassStatus.Text.Trim();
            string strNoPassStatus = tbNoPassStatus.Text.Trim();

            //配置
            Code.CatchConfig config = new Code.CatchConfig();
            config.ListXPath    = strListXPath;
            config.ItemXPath    = strItemXPath;
            config.TitleXPath   = strTitleXPath;
            config.PassStatus   = strPassStatus.Split(';').ToList();
            config.NoPassStatus = strNoPassStatus.Split(';').ToList();
            config.PagingXPath  = strPagingXPath;

            config = HandleConfig(config);

            Code.CatchCore catchCore = new Code.CatchCore(strUrl, strContent, config);
            var            result    = catchCore.Compute();

            if (result != null)
            {
                this.dataGridView1.DataSource = new BindingList <Code.ArticleModel>(result.ArticleList);
                string pageText = "";
                foreach (var li in result.PagingList)
                {
                    pageText += li + "\r\n";
                }
                rtbPage.Text = pageText;
            }
        }