Пример #1
0
        /// <summary>
        /// 测试采集内容
        /// </summary>
        private void btnTestViewUrl_Click(object sender, EventArgs e)
        {
            this.btnTestViewUrl.Enabled = false;
            this.txtTestViewUrlShow.Clear();
            var Test_ViewUrl = this.txtTextViewUrl.Text;
            var encode       = ((ListItem)this.ddlItemEncode.SelectedItem).Value;

            DALTaskLabel          dal            = new DALTaskLabel();
            List <ModelTaskLabel> Test_LabelList = new List <ModelTaskLabel>();

            ListView.ListViewItemCollection s = this.listViewTaskLabel.Items;
            foreach (ListViewItem ss in s)
            {
                Test_LabelList.Add(dal.GetModel(ss.SubItems[0].Text, ID));
            }

            var model = new ModelTask()
            {
                TestViewUrl = Test_ViewUrl,
                PageEncode  = encode
            };

            var task = new TaskFactory().StartNew(() => {
                var spiderViewHelper   = new SpiderViewHelper();
                spiderViewHelper.Model = model;
                spiderViewHelper.OutViewUrlContentHandler += (string content) => {
                    this.txtTestViewUrlShow.Invoke(new MethodInvoker(delegate() {
                        this.txtTestViewUrlShow.AppendText(content);
                        this.btnTestViewUrl.Enabled = true;
                    }));
                };
                spiderViewHelper.TestAllLabel(Test_ViewUrl, Test_LabelList);
            });
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            this.txtLogView.Clear();
            this.btnTest.Enabled = false;

            var model = new ModelTaskLabel();

            model.TestViewUrl       = this.txtTestUrl.Text;
            model.TaskID            = TaskID;
            model.LabelName         = this.txtLabelName.Text;
            model.LabelNameCutRegex = this.txtLabelNameCutRegex.Text.Replace("'", "''");
            model.LabelRemove       = string.Empty;
            model.LabelReplace      = string.Empty;

            #region Html¹ýÂË
            model.LabelHtmlRemove = string.Empty;
            if (this.chkAllHtml.Checked)
            {
                model.LabelHtmlRemove += "all||||";
            }
            if (this.chkTable.Checked)
            {
                model.LabelHtmlRemove += "table||||";
            }
            if (this.chkFont.Checked)
            {
                model.LabelHtmlRemove += "font<span>||||";
            }
            if (this.chkhref.Checked)
            {
                model.LabelHtmlRemove += "a||||";
            }
            if (this.chkScript.Checked)
            {
                model.LabelHtmlRemove += "script||||";
            }
            if (model.LabelHtmlRemove.Trim() != "")
            {
                model.LabelHtmlRemove = model.LabelHtmlRemove.Remove(model.LabelHtmlRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÅųý
            foreach (ListViewItem item in this.listViewContentRemove.Items)
            {
                model.LabelRemove += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelRemove.Trim() != "")
            {
                model.LabelRemove = model.LabelRemove.Remove(model.LabelRemove.Length - 4);
            }
            #endregion

            #region ÄÚÈÝÌæ»»
            foreach (ListViewItem item in this.listViewContentReplace.Items)
            {
                model.LabelReplace += item.SubItems[0].Text + "||" + item.SubItems[1].Text + "$$$$";
            }
            if (model.LabelReplace.Trim() != "")
            {
                model.LabelReplace = model.LabelReplace.Remove(model.LabelReplace.Length - 4);
            }
            #endregion

            model.IsLoop            = this.chkLabelIsLoop.Checked ? 1 : 0;
            model.SpiderLabelPlugin = this.cmbSpiderPlugin.Text;
            model.IsDownResource    = this.chkDownResource.Checked ? 1 : 0;
            model.DownResourceExts  = this.txtDownResourceExt.Text;

            var task = new System.Threading.Tasks.TaskFactory().StartNew(() => {
                var pageContent = CommonHelper.getPageContent(model.TestViewUrl, PageEncode);
                var spider      = new SpiderViewHelper();
                var s           = spider.TestSingleLabel(model, pageContent);

                this.Invoke(new MethodInvoker(() => {
                    this.btnTest.Enabled = true;
                    this.txtLogView.AppendText(s);
                    this.txtLogView.AppendText("\r\n");
                }));
            });
        }