首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

:WebBrowser

2013-03-25 
紧急求助:WebBrowser是想要读取 某网页的验证码。目前已经找到该验证码srcCheckCode.aspx,下一步该怎么

紧急求助:WebBrowser
是想要读取 某网页的验证码。

目前已经找到该验证码src="CheckCode.aspx",下一步该怎么办?


[解决办法]
验证码一般保存在session里,你需要取session信息
[解决办法]


            HttpWebRequest request;
            //验证码地址
            string picpath = "http://localhost:8034/Controls/ValidateCode.aspx";
            request = WebRequest.Create(picpath) as HttpWebRequest;
            request.Method = "GET";
            request.Timeout = 30000;
            request.AllowAutoRedirect = true;
            request.ContentType = "image/bmp";
            request.UserAgent = "Mozilla/5.0 (Windows NT 5.2; rv:11.0) Gecko/20100101 Firefox/11.0";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {

                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                Bitmap sourcebm = new Bitmap(sr.BaseStream);
                sr.Close();
                
              //SetLuma(sourcebm);//灰度处理
                //Repair(sourcebm);//修复
                pictureBox1.Image = sourcebm;
                //sourcebm.Save("veryfyCode.bmp");
                try
                {
                    /*
                    string _veryfyCode = Marshal.PtrToStringAnsi(OCR("veryfyCode.bmp", -1));
                    txt_Log.Text = _veryfyCode;
                    MessageBox.Show(_veryfyCode);
                     */


                    Tesseract tess=new Tesseract();
                    
                    Rectangle re= new Rectangle();
                    re.X = 0;
                    re.Y = 0;
                    re.Width = sourcebm.Width;
                    re.Height = sourcebm.Height;
                    string _veryfyCode=Tesseract.GetLineText(tess.DoOCR(sourcebm, re), 0);
                    MessageBox.Show(_veryfyCode);
                }
                catch (Exception error)
                {
                     MessageBox.Show(error.Message);
                }



他们讲用OCR来破解图片,我没试成功
[解决办法]
              string _veryfyCode=Tesseract.GetLineText(tess.DoOCR(sourcebm, re), 0);           MessageBox.Show(_veryfyCode); 

这个没有成功

热点排行