Exemplo n.º 1
0
        /// <summary>
        /// 获取cid
        /// </summary>
        /// <param name="postdata"></param>
        /// <returns></returns>
        private static string GetCid(string postdata, ref string newpostdata)
        {
            String cid  = String.Empty;
            String html = "start";

            try
            {
                HttpInfo info = new HttpInfo();
                info.RequestUrl        = Url;
                info.PostData          = postdata;
                info.AllowAutoRedirect = true;
                info.KeepLive          = true;
                while (!html.Contains("Search Result"))
                {
                    html = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                cid = RegexMethod.GetSingleResult(reg_cid, html, 1);
                String eventarget      = "__EVENTTARGET=" + RegexMethod.GetSingleResult(reg_newenent, html, 1).Replace("$", "%24");
                String eventargument   = "__EVENTARGUMENT=" + RegexMethod.GetSingleResult(reg_newenent, html, 2).Replace("$", "%24");
                String ViewState       = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                String EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                newpostdata = String.Format(Details_PostData, eventarget, eventargument, ViewState, EventValidation);
            }
            catch
            {
            }
            return(cid);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取详情页PostData
        /// </summary>
        /// <param name="Certi_No"></param>
        /// <param name="postdata"></param>
        /// <returns></returns>
        public static void GetDetailsPostData(string Certi_No, string postdata, ref ConcurrentQueue <string> postqueue)
        {
            String html = "start";

            try
            {
                while (!html.Contains("ERAC National Certification Database"))
                {
                    HttpInfo info = new HttpInfo();
                    info.RequestUrl = Url;
                    info.PostData   = postdata;
                    info.KeepLive   = true;
                    html            = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                List <string> list            = RegexMethod.GetMutResult(reg_arget, html, 1);
                String        ViewState       = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                String        EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        String detailpost = String.Format(Details_PostData, "__EVENTTARGET=" + item.Replace("&#39;", "").Replace("$", "%24"), ViewState, EventValidation, Certi_No);
                        postqueue.Enqueue(detailpost);
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取详情页
        /// </summary>
        /// <param name="Certi_No"></param>
        /// <returns></returns>
        public static Dictionary <string, string> ENEC_Details(string Certi_No)
        {
            Dictionary <string, string> dirs = new Dictionary <string, string>();
            String html = "start";

            try
            {
                HttpInfo info = new HttpInfo();
                info.RequestUrl        = Url;
                info.User_Agent        = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36";
                info.PostData          = String.Format(PostData, Certi_No);
                info.AllowAutoRedirect = true;
                info.KeepLive          = true;
                info.CC = new System.Net.CookieContainer();
                while (!html.Contains("Consultation of") && !html.Contains("licenced products"))
                {
                    html = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                //处理数据
                var list = RegexMethod.GetMutResult(reg_all, html, 1);
                if (list.Count > 1)
                {
                    var titlelist  = RegexMethod.GetMutResult(reg_title, list[0], 1);
                    var detaillist = RegexMethod.GetMutResult(reg_details, list[1], 1);
                    if (titlelist.Count == detaillist.Count)
                    {
                        for (int i = 0; i < titlelist.Count; i++)
                        {
                            if (i == titlelist.Count - 1)
                            {
                                if (detaillist[i].Contains("a href"))
                                {
                                    String moreall = RegexMethod.GetSingleResult(reg_moreurl, detaillist[i], 1);
                                    dirs.Add(titlelist[i], moreall);
                                }
                                else
                                {
                                    dirs.Add(titlelist[i], detaillist[i]);
                                }
                            }
                            else
                            {
                                dirs.Add(titlelist[i], detaillist[i]);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(dirs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取详情页
        /// </summary>
        /// <param name="Certi_No"></param>
        public static Dictionary <string, string> ERAC_Details(String detailspost, String Certi_No)
        {
            Dictionary <string, string> dirs = new Dictionary <string, string>();
            String html = String.Empty;

            try
            {
                HttpInfo info = new HttpInfo();
                info.PostData          = detailspost;
                info.AllowAutoRedirect = true;
                info.RequestUrl        = Url;
                while (!html.Contains("ERAC National Certification Database - "))
                {
                    html = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                //处理数据
                dirs.Add("CertNo", Certi_No);
                dirs.Add("Renewal_of", RegexMethod.GetSingleResult(reg_conditions, html, 1));
                dirs.Add("Description", RegexMethod.GetSingleResult(reg_des, html, 1));
                dirs.Add("Brand", RegexMethod.GetSingleResult(reg_brand, html, 1));
                dirs.Add("EquipmentClass", RegexMethod.GetSingleResult(reg_equi, html, 1));
                dirs.Add("Standard", RegexMethod.GetSingleResult(reg_stand, html, 1));
                dirs.Add("CertifiedDate", RegexMethod.GetSingleResult(reg_cerdate, html, 1));
                dirs.Add("ExpiryDate", RegexMethod.GetSingleResult(reg_expidate, html, 1));
                var    modellist = RegexMethod.GetMutResult(reg_model, html, 1);
                String model     = string.Empty;
                if (modellist.Count > 0)
                {
                    foreach (var modelitem in modellist)
                    {
                        model = model + modelitem + ";";
                    }
                }
                dirs.Add("Model", model);
                var    ratinglist = RegexMethod.GetMutResult(reg_rating, html, 1);
                String rating     = string.Empty;
                if (ratinglist.Count > 0)
                {
                    foreach (var ratingitem in ratinglist)
                    {
                        rating = rating + ratingitem + ";";
                    }
                }
                dirs.Add("Rating", rating);
            }
            catch
            {
            }
            return(dirs);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 正则抽取匹配结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (String.IsNullOrEmpty(html))
            {
                Form4 form4 = new Form4("错误:网页源码为空");
                form4.Text = "错误";
                form4.ShowDialog();
                return;
            }
            if (String.IsNullOrEmpty(textEdit9.Text))
            {
                Form4 form4 = new Form4("错误:正则表达式为空");
                form4.Text = "错误";
                form4.ShowDialog();
                return;
            }
            if (String.IsNullOrEmpty(textEdit10.Text))
            {
                Form4 form4 = new Form4("提示:层数为空,将使用默认值0");
                form4.Text = "提示";
                form4.ShowDialog();
                textEdit10.Text = "0";
            }
            richEditControl6.Text = "";
            int lay = Convert.ToInt32(textEdit10.Text);

            if (checkEdit11.Checked)
            {
                try
                {
                    var list = RegexMethod.GetMutResult(textEdit9.Text, html, lay);
                    richEditControl6.Text = String.Join("\n", list);
                }
                catch
                {
                    richEditControl6.Text = "未找到匹配结果";
                }
            }
            else
            {
                try
                {
                    richEditControl6.Text = RegexMethod.GetSingleResult(textEdit9.Text, html, lay);
                }
                catch
                {
                    richEditControl6.Text = "未找到匹配结果";
                }
            }
            barStaticItem1.Caption = "当前状态:正则抽取完成";
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取证书编号对应详情
        /// </summary>
        /// <param name="Certi_No"></param>
        private Dictionary <String, String> CQC_Details(String Certi_No)
        {
            Dictionary <String, String> dirs = new Dictionary <string, string>();
            HttpInfo info   = new HttpInfo();
            String   html   = "start";
            String   code   = String.Empty;
            String   cookie = Get_Cookie(CQC_Details_Url);

            try
            {
                while (!html.Contains(Certi_No) || html.Contains("验证码输入有误") || html.Contains("请输入验证码"))
                {
                    code            = WmCodeHelper.Get_Code(cookie);
                    info.RequestUrl = CQC_Details_Url;
                    info.PostData   = String.Format(CQC_PostData, Certi_No, code);
                    info.Cookie     = new CookieString(cookie, true);
                    //info.Ip = "";
                    html = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                if (html.Contains(Certi_No))
                {
                    //数据处理
                    var    ths   = XpathMethod.GetMutResult(xpath_title, html, 1);
                    var    strs  = XpathMethod.GetMutResult(xpath_certi, html, 1);
                    string fjurl = XpathMethod.GetSingleResult(xpath_certi + "[14]", html, 0);
                    fjurl = RegexMethod.GetSingleResult(reg_fjurl, fjurl, 1);
                    for (int i = 1; i < strs.Count; i++)
                    {
                        if (i == strs.Count - 1 && !String.IsNullOrEmpty(fjurl))
                        {
                            dirs.Add(ths[i], fjurl);
                        }
                        else
                        {
                            dirs.Add(ths[i], strs[i]);
                        }
                    }
                    //CCCInfo cccinfo = new CCCInfo();
                    //cccinfo.CertiNo = XpathMethod.GetSingleResult(xpath_certino, html);
                    //cccinfo.Applicant = XpathMethod.GetSingleResult(xpath_appli1, html) + "\r\n" + XpathMethod.GetSingleResult(xpath_appli2, html);
                }
            }
            catch
            {
            }
            return(dirs);
        }
Exemplo n.º 7
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(html))
            {
                MessageBox.Show("网页源码为空");
                return;
            }
            if (String.IsNullOrEmpty(textBox13.Text))
            {
                MessageBox.Show("正则表达式为空");
                return;
            }
            if (String.IsNullOrEmpty(textBox14.Text))
            {
                MessageBox.Show("层数为空,将使用默认值0");
                textBox14.Text = "0";
            }
            int lay = Convert.ToInt32(textBox14.Text);

            if (checkBox4.Checked)
            {
                try
                {
                    var list = RegexMethod.GetMutResult(textBox13.Text, html, lay);
                    richTextBox1.Text = String.Join("\n", list);
                }
                catch
                {
                    richTextBox1.Text = "未找到匹配结果";
                }
            }
            else
            {
                try
                {
                    richTextBox1.Text = RegexMethod.GetSingleResult(textBox13.Text, html, lay);
                }
                catch
                {
                    richTextBox1.Text = "未找到匹配结果";
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取PostData
        /// </summary>
        /// <param name="Certi_No"></param>
        /// <returns></returns>
        private static string GetPostData(String Certi_No)
        {
            String postdata = String.Empty;
            String html     = "start";

            try
            {
                while (!html.Contains("Online Search"))
                {
                    html = HttpMethod.FastGetMethod(Url);
                    Thread.Sleep(1);
                }
                String ViewState       = "__VIEWSTATE=" + RegexMethod.GetSingleResult(reg_view, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                String EventValidation = "__EVENTVALIDATION=" + RegexMethod.GetSingleResult(reg_event, html, 1).Replace("+", "%2B").Replace("/", "%2F").Replace("=", "%3D");
                postdata = String.Format(PostData, ViewState, EventValidation, Certi_No);
            }
            catch
            {
            }
            return(postdata);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 请求获取详细信息
        /// </summary>
        /// <param name="Certi_No"></param>
        public static Dictionary <string, string> TUVnd_Details(String Certi_No)
        {
            Dictionary <string, string> dirs = new Dictionary <string, string>();
            String html = "start";

            try
            {
                HttpInfo info = new HttpInfo();
                info.RequestUrl = String.Format(Url, Certi_No);
                while (!html.Contains(Certi_No))
                {
                    html = HttpMethod.HttpWork(info);
                    Thread.Sleep(1);
                }
                //处理数据
                var list = RegexMethod.GetMutResult(reg_all, html, 1);
                int i    = 0;
                foreach (var item in list)
                {
                    if (item.Contains("cert_details_th"))
                    {
                        String title   = RegexMethod.GetSingleResult(reg_title, item, 1);
                        String details = RegexMethod.GetSingleResult(reg_details, item, 1);
                        if (title != "&#160;" && details != "&#160;")
                        {
                            if (String.IsNullOrEmpty(title))
                            {
                                i++;
                                title = "Custom" + i;
                            }
                            dirs.Add(title, details);
                        }
                    }
                }
            }
            catch
            {
            }
            return(dirs);
        }
Exemplo n.º 10
0
        private void RunFunc(string xpathstr, string regstr, string proxyapi_url, bool timeflag, string ip)
        {
            GC.Collect();
            UpRichTextBox uptxt = new UpRichTextBox(UpRichTxt);

            #region 请求前检查
            if (String.IsNullOrEmpty(info.RequestUrl))
            {
                Form4 form4 = new Form4("错误,请求地址不合法");
                form4.Text = "错误";
                form4.ShowDialog();
                return;
            }
            #endregion

            #region 配置请求头
            HttpInfo info_goto = CreateHttp();
            if (!String.IsNullOrEmpty(ip))
            {
                info_goto.Ip = ip;
            }
            #endregion
            double    time = 0;
            Stopwatch sw   = new Stopwatch();
            if (timeflag)
            {
                sw.Start();
            }
            String Html = HttpMethod.HttpWork(ref info_goto);
            if (sw.IsRunning)
            {
                sw.Stop();
                time = sw.Elapsed.TotalSeconds;
            }
            String cookie = info_goto.Cookie.ConventToString();
            String _ip    = info_goto.Ip;

            #region 正则判断访问结果
            if (!String.IsNullOrEmpty(regstr) && String.IsNullOrEmpty(xpathstr))
            {
                String regtxt = RegexMethod.GetSingleResult(regstr, Html);
                String status = String.Empty;
                String txt    = String.Empty;
                if (String.IsNullOrEmpty(regtxt))
                {
                    status = "访问失败";
                }
                else
                {
                    status = "访问成功";
                }
                if (timeflag)
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n";
                    }
                }
                object[] arg = { txt };
                this.Invoke(uptxt, arg);
            }
            #endregion

            #region Xpath判断访问结果
            if (!String.IsNullOrEmpty(xpathstr) && String.IsNullOrEmpty(regstr))
            {
                String regtxt = XpathMethod.GetSingleResult(xpathstr, Html);
                String status = String.Empty;
                String txt    = String.Empty;
                if (String.IsNullOrEmpty(regtxt))
                {
                    status = "访问失败";
                }
                else
                {
                    status = "访问成功";
                }
                if (timeflag)
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + status + "\r\n" + "ret-cookie:" + cookie + "\r\n";
                    }
                }
                object[] arg = { txt };
                this.Invoke(uptxt, arg);
            }
            #endregion

            #region 直接输出结果
            if (String.IsNullOrEmpty(regstr) && String.IsNullOrEmpty(xpathstr))
            {
                String txt = String.Empty;
                if (timeflag)
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求时间:" + time + "\r\n";
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(proxyapi_url))
                    {
                        txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n" + "请求IP:" + _ip + "\r\n";
                    }
                    else
                    {
                        txt = "返回结果:" + Html + "\r\n" + "ret-cookie:" + cookie + "\r\n";
                    }
                }
                object[] arg = { txt };
                this.Invoke(uptxt, arg);
            }
            #endregion
        }
Exemplo n.º 11
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //Form1 form1 = new Form1();
            string key = string.Empty;

            if (!checkEdit1.Checked)
            {
                switch (comboBoxEdit1.SelectedIndex)
                {
                case 0:
                    key = "Host";
                    break;

                case 1:
                    key = "ProtocolVersion";
                    break;

                case 2:
                    key = "proxy";
                    break;
                }
                if (comboBoxEdit1.SelectedIndex == 0)
                {
                    if (String.IsNullOrEmpty(textEdit1.Text))
                    {
                        Form4 form4 = new Form4("警告:请填写Host的Value值");
                        form4.Text = "警告";
                        form4.ShowDialog();
                        return;
                    }
                    if (Form1.HeadDic.TryAdd(key, textEdit1.Text))
                    {
                    }
                    else
                    {
                        Form4 form4 = new Form4("错误:Key已存在");
                        form4.Text = "错误";
                        form4.ShowDialog();
                    }
                }
                if (comboBoxEdit1.SelectedIndex == 1)
                {
                    if (textEdit1.Text == "1.1")
                    {
                        if (Form1.HeadDic.TryAdd(key, "1.1"))
                        {
                        }
                        else
                        {
                            Form4 form4 = new Form4("错误:Key已存在");
                            form4.Text = "错误";
                            form4.ShowDialog();
                        }
                    }
                    else
                    {
                        if (Form1.HeadDic.TryAdd(key, "1.0"))
                        {
                        }
                        else
                        {
                            Form4 form4 = new Form4("错误:Key已存在");
                            form4.Text = "错误";
                            form4.ShowDialog();
                        }
                    }
                }
                if (comboBoxEdit1.SelectedIndex == 2)
                {
                    string str = RegexMethod.GetSingleResult("[0-9]+?.[0-9]+?.[0-9]+?.[0-9]+?:[0-9]+", textEdit1.Text);
                    if (String.IsNullOrEmpty(textEdit1.Text) || String.IsNullOrEmpty(str))
                    {
                        Form4 form4 = new Form4("警告:请按指定格式填写Proxy的Value值");
                        form4.Text = "警告";
                        form4.ShowDialog();
                        return;
                    }
                    if (Form1.HeadDic.TryAdd(key, textEdit1.Text))
                    {
                    }
                    else
                    {
                        Form4 form4 = new Form4("错误:Key已存在");
                        form4.Text = "错误";
                        form4.ShowDialog();
                    }
                }
            }
            else
            {
                if (String.IsNullOrEmpty(textEdit1.Text) || String.IsNullOrEmpty(textEdit2.Text))
                {
                    Form4 form4 = new Form4("警告:请填写自定义的key和Value值");
                    form4.Text = "警告";
                    form4.ShowDialog();
                    return;
                }
                if (Form1.HeadDic.TryAdd(textEdit2.Text, textEdit1.Text))
                {
                }
                else
                {
                    Form4 form4 = new Form4("错误:Key已存在");
                    form4.Text = "错误";
                    form4.ShowDialog();
                }
            }
            key = null;
            this.Close();
        }