Exemplo n.º 1
0
        //提取表单内容
        public void GetProductFormContent()
        {
            if (string.IsNullOrEmpty(productPage))
            {
                auctionLog.Log("警告:传递的商品页源代码字符串为空");
                return;
            }

            //提取问题并要求回答
            Match questionMatch = Regex.Match(productPage, "<div\\s*class\\s*=\\s*\"\\s*disqualified\\s*\".*?<\\s*br.*?>(?<question>.*?)\\s*<\\s*/\\s*div>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (questionMatch.Success)
            {
                string          question        = string.Empty;
                string          questionContent = questionMatch.Groups["question"].ToString();
                MatchCollection charMatches     = Regex.Matches(questionContent, "&#(?<number>\\d+)\\s*;", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (charMatches.Count > 0)
                {
                    foreach (Match match in charMatches)
                    {
                        int charNumber = int.Parse(match.Groups["number"].ToString());
                        question += Convert.ToChar(charNumber);
                    }
                }
                if (!string.IsNullOrEmpty(question))
                {
                    /*
                     * questionForm.lblQuestion.Text = question;
                     * questionForm.ShowDialog();
                     * questionAnswer = questionForm.txtAnswer.Text.Trim();
                     */
                }
            }

            string frmContent, inputContent, tempStr;
            Match  tempMatch;

            MatchCollection matches = Regex.Matches(productPage, "<form\\s+id\\s*=\\s*\"J_FrmBid\"\\s+.*?>.*?<\\s*/\\s*form\\s*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (matches.Count > 0)
            {
                auctionLog.Log("通知:发现了商品页面中表单");
                frmContent = matches[0].ToString();
                //提取各个input控件的内容存入dict字典
                matches = Regex.Matches(frmContent, "<\\s*input.*?>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (matches.Count > 0)
                {
                    auctionLog.Log("通知:在商品页面的表单中发现了input控件");
                    foreach (Match match in matches)
                    {
                        inputContent = match.ToString();
                        tempMatch    = Regex.Match(inputContent, "name\\s*=\\s*[\"\'](?<name>.*?)[\"\']", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        if (tempMatch.Success)
                        {
                            tempStr = tempMatch.Groups["name"].ToString();
                            productInputDict.Add(tempStr, "");
                            tempMatch = Regex.Match(inputContent, "value\\s*=\\s*[\"\'](?<value>.*?)[\"\']", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            productInputDict[tempStr] = tempMatch.Groups["value"].ToString();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        //获取表单控件列表
        private void GetOrderFormContent(string orderPage)
        {
            string frmContent, inputContent;
            Match  tempMatch;

            MatchCollection matches = Regex.Matches(orderPage, "<form\\s+id\\s*=\\s*\"J_Form\"\\s+.*?>.*?<\\s*/\\s*form\\s*>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);

            if (matches.Count > 0)
            {
                auctionLog.Log("通知:发现了订单页面中的表单");
                frmContent = matches[0].ToString();

                //读取获取newCheckCode的地址
                tempMatch = Regex.Match(frmContent, "J_checkCodeUrl.*?value\\s*=\\s*\"(?<checkCodeUrl>.*?)\"", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (tempMatch.Success)
                {
                    checkCode.J_checkCodeUrl = tempMatch.Groups["checkCodeUrl"].ToString();
                }

                matches = Regex.Matches(frmContent, "<\\s*(?<control>input|textarea|select).*?>", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (matches.Count > 0)
                {
                    auctionLog.Log("通知:发现了订单页面表单中的input控件");
                    foreach (Match match in matches)
                    {
                        InputControl inputControl = new InputControl();

                        inputContent = match.ToString();
                        tempMatch    = Regex.Match(inputContent, "name\\s*=\\s*[\"\'](?<name>.*?)[\"\']", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        if (tempMatch.Success)
                        {
                            inputControl.Control = match.Groups["control"].ToString();

                            inputControl.Name = tempMatch.Groups["name"].ToString();

                            tempMatch = Regex.Match(inputContent, "value\\s*=\\s*[\"\'](?<value>.*?)[\"\']", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            if (tempMatch.Success)
                            {
                                inputControl.Value = tempMatch.Groups["value"].ToString();
                            }

                            tempMatch = Regex.Match(inputContent, "type\\s*=\\s*[\"\'](?<type>.*?)[\"\']", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                            if (tempMatch.Success)
                            {
                                inputControl.Type = tempMatch.Groups["type"].ToString();
                            }

                            inputControls.Add(inputControl);

                            //读取获取newCheckCode所需的信息
                            if (inputControl.Name.Trim().ToLower() == "ischeckcode" && inputControl.Value.Trim().ToLower() == "true")
                            {
                                checkCode.isCheckCode = "true";
                            }

                            if (inputControl.Name.Trim().ToLower() == "encrypterstring")
                            {
                                checkCode.encrypterString = inputControl.Value;
                            }

                            if (inputControl.Name.Trim().ToLower() == "sid")
                            {
                                checkCode.sid = inputControl.Value;
                            }

                            if (inputControl.Name.Trim().ToLower() == "gmtcreate")
                            {
                                checkCode.gmtCreate = inputControl.Value;
                            }

                            if (inputControl.Name.Trim().ToLower() == "checkcodeids")
                            {
                                checkCode.checkCodeIds = inputControl.Value;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        //获取验证码验证信息的方法
        public string GetNewCheckCode(OrderPageHandle.CheckCode checkCode, CookieContainer ccEntered, out CookieCollection ccReturned)
        {
            if (string.IsNullOrEmpty(checkCode.J_checkCodeUrl))
            {
                auctionLog.Log("警告:获取newCheckCode的URL地址为空");
                ccReturned = new CookieCollection();
                return(string.Empty);
            }

            HttpWebRequest  request;
            HttpWebResponse response;

            string queryString = "isCheckCode=" + checkCode.isCheckCode + "&"
                                 + "encrypterString=" + checkCode.encrypterString + "&"
                                 + "sid" + checkCode.sid + "&"
                                 + "gmtCreate" + checkCode.gmtCreate + "&"
                                 + "checkCodeIds" + checkCode.checkCodeIds + "&"
                                 + "checkCode=" + checkCode.checkCode;

            request = (HttpWebRequest)HttpWebRequest.Create(checkCode.J_checkCodeUrl + "?" + queryString);

            request.Method          = "GET";
            request.ProtocolVersion = HttpVersion.Version11;
            //request.Connection = "keep-alive";
            request.ContentType = " application/x-www-form-urlencoded; charset=UTF-8";
            request.UserAgent   = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.861.0 Safari/535.2";
            request.Accept      = "*/*";
            request.Referer     = "http://buy.taobao.com/auction/buy_now.jhtml";

            //request.Headers.Add("Connection", "keep-alive");

            request.Headers.Add("X-Requested-With", "XMLHttpRequest");
            request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
            request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
            request.Headers.Add("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");

            request.CookieContainer = ccEntered;

            request.AllowAutoRedirect = true;

            response = (HttpWebResponse)request.GetResponse();

            ccReturned = response.Cookies;

            Stream st;

            st = response.GetResponseStream();

            if (response.ContentEncoding.ToLower().Contains("gzip"))
            {
                st = new GZipStream(st, CompressionMode.Decompress, true);
            }

            string htmlText = string.Empty;

            StreamReader stReader = new StreamReader(st, Encoding.GetEncoding("gb2312"));

            htmlText = stReader.ReadToEnd();

            stReader.Close();
            st.Close();

            auctionLog.ShowTextInForm(response.ResponseUri.ToString(), htmlText);
            response.Close();

            return(htmlText);
        }