根据运单号来获取运单状态 以EMS快递为例:

 

第一步首先分析要抓取网站的入口及参数 http://www.ems.com.cn

第二部利用httpwebRequest 模拟浏览器请求来获取网页内容

利用HttpWebRequest抓取网页数据

上图可以看到 获取验证码请求

http://www.ems.com.cn/ems/rand

查询

利用HttpWebRequest抓取网页数据

可以看到 发送的 post请求 http://www.ems.com.cn/ems/order/singleQuery_t

 public void getcode()
        {

          
            
            string code = "";
            HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("http://www.ems.com.cn/ems/rand");
            hwr.Timeout = 30000;
            //hwr.ReadWriteTimeout = 5 * 1000;
            HttpWebResponse res;
            try
            {
                res = (HttpWebResponse)hwr.GetResponse();
                string[] s = res.Headers["Set-Cookie"].ToString().Split(';');
                _cookieConE = s[0].ToString();
                _cookieConE2 = s[2].ToString();
            }
            catch (WebException ex)
            {
                //
                 n++;
                if( n<=3)//同一个运单如果验证码获取三次后还是有异常就跳出进行下一个运单获取
                {
                    getcode();

                }
                res = (HttpWebResponse)ex.Response;
            }
           

            
            Bitmap bmp = new Bitmap(res.GetResponseStream());
            Bitmap bit2 = Crop(bmp, 5, 0, 78, 20);
            Base.YZ y = new Base.YZ(bit2);
            y.GrayByPixels(); //灰度处理
            y.GetPicValidByValue(128, 6); //得到有效空间
            Bitmap[] pics = y.GetSplitPics(6, 1);     //分割
            for (int i = 0; i < pics.Length; i++)
            {
                code = code + "%" + y.GetSingleBmpCode(pics[i], 128);
            }
            string[] arry = code.Split('%');
            result = y.CheckNumber(arry);
            if (result.Length < 6)//获取验证码有成功率 
            {
                n++;
                getcode();
            }
            n = 0;

         
            #endregion
        }
getread获取验证码

相关文章:

  • 2021-05-22
  • 2021-12-13
  • 2022-02-07
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-22
  • 2021-09-25
  • 2021-11-29
  • 2021-12-15
  • 2021-12-04
相关资源
相似解决方案