Get Captcha Image in PictureBox [VB.NET]

There is the source to get a ReCaptcha Image into your PictureBox. This only works for ReCaptcha so far. Will be making more soon.

Theres 2 Methods:
1) Put this Sub in your Project.
You need:

  • PictureBox –> name = PictureBox1
  • WebBrowser –> name = WebBrowser1

getcaptcha()

Code:
Public Sub getcaptcha()
  Dim str As String = WebBrowser1.Document.GetElementById("recaptcha_image").InnerHtml 'Gets the html code for the recaptcha_image element
  Dim img As String = str.Remove(0, 33).Replace(""" width=300 height=57>", "") 'Deletes all the info around the link because the height and width will never change
  PictureBox1.ImageLocation = img 'Sets the ImageLocation to the URL of the ReCaptcha Image
    End Sub

Then find the WebBrowser1 Document Completed Sub (shown below)

Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

  End Sub

And Add this code below to the Sub Above ^^

Code:
If WebBrowser1.DocumentTitle.Contains("Emk") Then
    getcaptcha() 'Runs the sub getcaptcha()
  End If

So it would look like this

Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    getcaptcha() 'Runs the sub getcaptcha()

  End Sub

Here is the whole source of the program if you don’t want to download…

Code:
Public Class Form1

    'Give credits if you're gonna use!
    'From Brad of HF
    'Free Source code for Finding ReCaptcha Image and displaying in PictureBox on a form.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  WebBrowser1.Navigate("http://emkei.cz/") 'Website that has the ReCaptcha
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
  If WebBrowser1.DocumentTitle.Contains("Emk") Then
    Button1.Enabled = True 'Enables DoCaptcha button
    Button2.Enabled = True 'Enables Get New Captcha button
    Button3.Enabled = True ' Enables Play button
    getcaptcha() 'Runs the sub getcaptcha()
  End If
  If WebBrowser1.Url.AbsolutePath.Contains("reload") Then
    getcaptcha() 'Runs the sub getcaptcha()
  End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  WebBrowser1.Document.GetElementById("recaptcha_response_field").InnerText = TextBox1.Text 'Sets the Captcha text box
  'With info you put in the textbox1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  WebBrowser1.Navigate("javascript:Recaptcha.reload ();") 'Runs the Captcha Reload function
  PictureBox1.ImageLocation = "A" 'Changes the ImageLocation
  MsgBox("Captcha changed successfully.") 'Uses the messagebox because without it, it has some problems on timing. Could use system.threading.thread.sleep(7000) instead.
  getcaptcha() 'Runs the sub getcaptcha()
    End Sub

    Public Sub getcaptcha()
  Dim str As String = WebBrowser1.Document.GetElementById("recaptcha_image").InnerHtml 'Gets the html code for the recaptcha_image element
  Dim img As String = str.Remove(0, 33).Replace(""" width=300 height=57>", "") 'Deletes all the info around the link because the height and width will never change
  PictureBox1.ImageLocation = img 'Sets the ImageLocation to the URL of the ReCaptcha Image
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  WebBrowser1.Navigate("javascript:Recaptcha.switch_type('audio');") 'Plays the audio of the ReCaptcha
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  WebBrowser1.Navigate("http://www.hackforums.net/private.php?action=send&uid=215721") 'Goes to my Profile (Brad (tm)) and sends a PM. Probably won't work cause you gotta login.
    End Sub
End Class

2) Download my Source code. It says Get Youtube Captcha but it really doesn’t so just a heads up. Download link is http://dl.dropbox.com/u/11786922/Get%20Y…aptcha.zip

Screenshot

[Image: program.png]

This isn’t an auto Captcha all it does it get the image from the website and put it in a PictureBox.

2 Comments
  1. Reply
    andrew siddle September 5, 2011 at 3:18 pm

    if any body want some information about Captcha Code i will refer him this blog..
    Good work…

  2. Reply
    beshoy maher February 28, 2014 at 6:07 am

    hi
    can i get help
    how can show captcha in PictureBox
    code
    [code]
    <img src="/alpha/captcha.php?1393542946" width="150" height="25" title="Click for another image" alt="CAPTCHA" id="asc"[/code]

Leave a reply