Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT]getting reCaptcha image in picturebox[TUT]

here is a tutorial for getting reCaptcha image into a picture box.
Ok lets get to the point of getting reCaptcha image.

1. first download the page using httpwebrequest
2. then parse the reCaptcha url
3. goto that challenge url and you'll find the actual "key" for that image
4. parse that key and goto http://www.google.com/recaptcha/api/image?c=PARSED_KEY to get the image
Code
Dim request As HttpWebRequest = HttpWebRequest.Create("www.pagewithcaptcha.com")

Dim response as HttpWebResponse
response = CType(request.GetResponse, HttpWebResponse)
    Dim webstream As Stream = response.GetResponseStream
    Dim streamreader As New StreamReader(webstream, Encoding.UTF8)

    Dim html As String = streamreader.ReadToEnd

'Now we have the source of the page lets parse and get the challenge url

Dim web As IHTMLDocument2 = New HTMLDocumentClass()
web.write(html)
web.close()

Dim allElements As IHTMLElementCollection = web.body.all
Dim allInputs As IHTMLElementCollection = allElements.tags("script")
Dim element As IHTMLElement

Dim challengeUrl As String = ""

Dim tagName As String = ""
  For Each element In allScript
    tagName = element.getAttribute("src")
    If (Not tagName = Nothing) Then
    If (tagName.Contains("http://api.recaptcha.net/")) Then
    challengeUrl = tagName
    Exit For
    End If
    End If
  Next

'Now we have the challenge url in challengeUrl variable, so lets "GET" it

Dim request1 As HttpWebRequest = HttpWebRequest.Create(challengeUrl)

Dim response1 as HttpWebResponse
response1 = CType(request1.GetResponse, HttpWebResponse)
    Dim webstream As Stream = response1.GetResponseStream
    Dim streamreader As New StreamReader(webstream, Encoding.UTF8)

    Dim temp As String = streamreader.ReadToEnd

'Now parse the index or whatever of that image, it is the thing that we are looking after

Dim startPos As Integer = temp.IndexOf("challenge : '")
    startPos += 13
    temp = temp.Substring(startPos)
    Dim endPos As Integer = temp.IndexOf("'")

    temp = (temp.Substring(0, endPos))

'Now the temp variabloe contains the key for the image.. You can download the image from

"http://www.google.com/recaptcha/api/image?c=" & temp

This code is fragmented so may not work by just copying and pasting...

I wrote this while making Pligg submitter bot which isnt complete. You can help me if you can here
Why not just fetch the url? And load it in a picturebox?

Code
Dim str As String = New StreamReader(HttpWebRequest.Create("http://captchas.net/registration/").GetResponse.GetResponseStream).ReadToEnd
  PictureBox1.Image = Image.FromStream(HttpWebRequest.Create((GetBetween(str, "id=""captchas.net"" src=""", """ width=""240""")).Replace("amp;", Nothing)).GetResponse.GetResponseStream())

Sorry if I misunderstood you.
FR1908
(Jun 7, 2011 05:11 AM)jangedoo Wrote:  here is a tutorial for getting reCaptcha image into a picture box.
Ok lets get to the point of getting reCaptcha image.

1. first download the page using httpwebrequest
2. then parse the reCaptcha url
3. goto that challenge url and you'll find the actual "key" for that image
4. parse that key and goto http://www.google.com/recaptcha/api/image?c=PARSED_KEY to get the image
Code
Dim request As HttpWebRequest = HttpWebRequest.Create("www.pagewithcaptcha.com")

Dim response as HttpWebResponse
response = CType(request.GetResponse, HttpWebResponse)
    Dim webstream As Stream = response.GetResponseStream
    Dim streamreader As New StreamReader(webstream, Encoding.UTF8)

    Dim html As String = streamreader.ReadToEnd

'Now we have the source of the page lets parse and get the challenge url

Dim web As IHTMLDocument2 = New HTMLDocumentClass()
web.write(html)
web.close()

Dim allElements As IHTMLElementCollection = web.body.all
Dim allInputs As IHTMLElementCollection = allElements.tags("script")
Dim element As IHTMLElement

Dim challengeUrl As String = ""

Dim tagName As String = ""
  For Each element In allScript
    tagName = element.getAttribute("src")
    If (Not tagName = Nothing) Then
    If (tagName.Contains("http://api.recaptcha.net/")) Then
    challengeUrl = tagName
    Exit For
    End If
    End If
  Next

'Now we have the challenge url in challengeUrl variable, so lets "GET" it

Dim request1 As HttpWebRequest = HttpWebRequest.Create(challengeUrl)

Dim response1 as HttpWebResponse
response1 = CType(request1.GetResponse, HttpWebResponse)
    Dim webstream As Stream = response1.GetResponseStream
    Dim streamreader As New StreamReader(webstream, Encoding.UTF8)

    Dim temp As String = streamreader.ReadToEnd

'Now parse the index or whatever of that image, it is the thing that we are looking after

Dim startPos As Integer = temp.IndexOf("challenge : '")
    startPos += 13
    temp = temp.Substring(startPos)
    Dim endPos As Integer = temp.IndexOf("'")

    temp = (temp.Substring(0, endPos))

'Now the temp variabloe contains the key for the image.. You can download the image from

"http://www.google.com/recaptcha/api/image?c=" & temp

This code is fragmented so may not work by just copying and pasting...

I wrote this while making Pligg submitter bot which isnt complete. You can help me if you can here

What's with all the extra nonsense? This is like a mix between using WebRequests and the WebBrowser component. Why? Why not just manipulate the Html directly with strings. Why convert it to an IHTMLDocument2? All that is doing is resulting in more work/code. If you have a good explanation as to why you are doing this, that's fine... I'm just curious as to why you'd want to make more work for yourself.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by xx1ben99xxApr 7, 2020 02:45 PM 10 311 Apr 7, 2020 02:45 PM
Last Post: xx1ben99xx
[C#] by C++Dec 29, 2019 06:16 PM 16 831 Dec 29, 2019 06:16 PM
Last Post: DNA
[.NET] by ShapelessSep 27, 2019 12:15 PM 16 614 Sep 27, 2019 12:15 PM
Last Post: 0xDEAD10CC