1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How can I download a captcha into a picture box so that I can type it in?

Discussion in 'Visual Basic .NET' started by simpleonline1234, May 7, 2011.

  1. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    I have an app that will sign me up for about 20 websites at once and each one requires a captcha to prove your human (which is cool I don't mind typing them in). I have a form 2 that is going to pop up with all the captchas viewed in picture boxes with textboxes for me to enter my text and submit buttons to enter the captcha to the website.

    The only issue that I am having is getting the captcha to view in the picture box. It refreshes everytime I get it to showup.

    I had it working previously but my hard drive crashed and I lost the code and the app.

    From what I was able to put together previously I was able to grab the element by type and if the src hadgoogle then to put the source into the picture box.

    I tried to rework it all day yesterday and I just keep getting the code refreshing.

    Any ideas on why it's not working?

    Here the code.

    Code:
    Public Class Form1
    
     
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            WebBrowser1.Navigate("httpsdotdot//secure.diigo.com/sign-up?referInfo=http%3A%2F%2Fwwwdotdiigodotcom") '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)
            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 PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    
        End Sub
    End Class
     
  2. lwelch45

    lwelch45 Junior Member

    Joined:
    Mar 24, 2010
    Messages:
    135
    Likes Received:
    38
    Home Page:
    That code looks soooooooooooo familiar. HF
     
  3. gnote

    gnote Registered Member

    Joined:
    Mar 10, 2009
    Messages:
    80
    Likes Received:
    6
    Occupation:
    Programmer
    Location:
    USA
    hmm im not certain that it works this way, but if you said you've done it before then i can't argue.

    when i coded a browser captcha typer, i had to copy the image element to the clipboard and save it as binary to a temp.jpg file. one thing to note here is when you load the image file to the picture box you should use a filestream to prevent IO locks.
    you can find the code on google
    http://www.google.com/search?q=webb...s=org.mozilla:en-US:official&client=firefox-a

    or heres a good prospect
    http://stackoverflow.com/questions/3833718/webbrowser-copy-image-to-clipboard
     
  4. andee

    andee Regular Member

    Joined:
    Jul 24, 2010
    Messages:
    218
    Likes Received:
    83
    if you press the back button in your browser, and look 10 threads down youll get your answer...

    i cant post link (f*ck you bhw what a pain in the ass, lol, its been ages already) but the threads called

    how save captcha image picturebox webbrowser not webrequest