7
Answers

How can I display a captcha image in a picture box

Dav Lewis

Dav Lewis

10y
2.1k
1
Hi
 
I've just started trying to learn visual basic and I'm trying to to display a captcha image in a picture box.
The site Im trying to make the desktop app for is https://emkei.cz/
Here is the code that I've done so far. 
 
  
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
         Call navigatetosite()
    End Sub
 
    Private Sub navigatetosite()
        Try
            WebBrowser1.Navigate("https://emkei.cz/", False)
            While WebBrowser1.Readystate <> WebBrowserReadyState.Complete
                Application.DoEvents()
            End While
            Call getcaptcha()
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
    End Sub
 
    Private Sub getcaptcha()
        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("scr").ToString.Contains("https://www.google.com/recaptcha/api/") Then
                imgRange.add(img)
                imgRange.execCommand("copy", False, Nothing)
                PictureBox1.Image = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
                Exit For
            End If
        Next
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        WebBrowser1.Document.GetElementById("fromname").SetAttribute("value", TextBox1.Text)
    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        WebBrowser1.Document.GetElementById("from").SetAttribute("value", TextBox2.Text)
    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
        WebBrowser1.Document.GetElementById("rcpt").SetAttribute("value", TextBox3.Text)
    End Sub

    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
        WebBrowser1.Document.GetElementById("subject").SetAttribute("value", TextBox4.Text)
    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
        WebBrowser1.Document.GetElementById("text").SetAttribute("value", TextBox5.Text)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        WebBrowser1.Document.GetElementById("btn").InvokeMember("click")
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

    End Sub

    Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
        WebBrowser1.Document.GetElementById("recaptcha_response_field").SetAttribute("value", TextBox6.Text)
    End Sub
End Class
 
 
 Like I say I've just started so all help and advice would be very much appreciated.
 
Thank You  
 
Answers (7)