Quantcast
Channel: 飘逸的轮子
Viewing all articles
Browse latest Browse all 12

如何提取网页中验证码图(流方式返回的图片)

$
0
0
很多网站一些图片是动态生成了,是从服务器以流方式一点点发过来再组装成图片的。不管是以什么方式,到了客户端,都是完整的。用WebBrowser的好处就在这里,只要管住最终结果就OK了。以下是得到网页上验证码的代码:

        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
       private Image GetWebImage(WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument doc = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody body = (HTMLBody)doc.body;
            IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();
            rang.add(Img);
            rang.execCommand("Copy", false, null); //拷贝到内存
            Image numImage = Clipboard.GetImage(); //从 Clipboard中取图
             Clipboard.SetImage(oldImage);      //还原
            return numImage;
        }


 

Viewing all articles
Browse latest Browse all 12

Trending Articles