0

有没有办法从 webwiev 网站复制验证码图像,然后将其粘贴到 imagewiev 中?我曾经在 VB.NET 中工作,所以我正在尝试一些新的东西。这是代码形式 vb :

Private Sub captcha()
     Dim doc As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument

     Dim imgrange As mshtml.IHTMLControlRange = CType(doc.body, mshtml.HTMLBody).createControlRange
        For Each img As mshtml.IHTMLImgElement In doc.images
            If img.getattribute("src").ToString.Contains("jkjkhjkhjk") Then
                imgrange.add(img)
                imgrange.execCommand("copy", False, Nothing)
                PictureBox1.Image = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
                Exit For
            End If
        Next
End Sub
4

1 回答 1

0

无法粘贴到 imageView 中,只需加载 Web 视图即可。像那样,

 [self.captchaWebView loadHTMLString:@"<html><head><style type='text/css'>a {color:white;font-size:20px;font-style:bold}small{color:white;font-size:20px;font-style:bold}</style><script type='text/javascript'>var a = 49; b= 65; var c =100; var d = 70;var f=85;function DrawCaptcha(){if(a==57){a=49;}var main = document.getElementById('captchaText'); var a1=String.fromCharCode(a);var b1=String.fromCharCode(b);var c1=String.fromCharCode(c);var d1=String.fromCharCode(d);var f1=String.fromCharCode(f);main.innerHTML = a1+b1+c1+d1+f1;a=a+1;b=b+1;c=c+1;d=d+1;f=f+1;}function ValidCaptcha(){var str1=document.getElementById('captchaText').innerHTML;var str2=document.getElementById('txtinput').value;if(str1==str2)return true;return false;}</script></head><body bgcolor = 'rgb(231,184,17)'><lable style='font-size:28px;'><font color='white' face = 'helevetica Bold'><b>&nbsp;&nbsp;&nbsp;Enter Captcha</b></font></label><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='captchaText' style='font-size:25pt;font-family:Chalkduster'>5Klne</span><br/><br/><input type='text' style=border:none;font-size:20px;height:40px' id='txtinput' /><br/><br/>&nbsp;&nbsp;<small>Can't read this? </small><a href='#' onclick='DrawCaptcha()'>try another</a></body></html>" baseURL:nil];
于 2013-09-06T04:27:35.113 回答