Sep 27, 2011 05:35 PM
(This post was last modified: Nov 20, 2011 03:59 AM by Milopeach.)
I don't know if this is appropriately named, So If anyone has a better one throw it in with your response.
Rundown:
This tutorial will show you how to get almost every captcha within a webpage that's loaded into your web browser in your VB.NET (Possibly VB, I've never tried) project.
Alright, So let's begin.
Step 1:
Find your webpage that contains the captcha image, Today I'll be using Google's Gmail registration page located here, or https://accounts.google.com/NewAccount for reference. (I trimmed the extension off so we have a clean load every time.)
Step 2:
Scroll down to your captcha, select the image (highlight the image with the cursor), right click and view the source of the image. (Most browsing clients have this functionality - I'm using Mozilla 3.6)
Reference Image:
![[Image: kwUZg.png]](https://i.imgur.com/kwUZg.png)
Step 3:
Now that we have the captcha's HTML source (above) We can use this for our Captcha script in our VB.NET Project. For our project, we only need an outstanding and static, piece of information from the URL. This means, anything that changes has to go and something that stays the same we keep.
Example: The URL is https://accounts.google.com/Captcha?ctoken=W1z6d...b9Q - Now, everthing after ?ctoken= is dynamic, so we don't want to use that to get the captcha otherwise we'll get a new captcha. Thus, giving us the only option of using everything before the dynamic part. (3h7ghdasdgh17g etc) I tend to use the Captcha?, We'll be using this in our VB.NET Source.
Step 4: - Getting down to the coding.
Open a new Project in your IDE (Visual Basic 08/10 etc) and make it a Windows Forms Application.
This step is vitally important! - In the menustrip of your IDE (Microsoft Visual Basic Express 08 for me) There should be a Project Button, Open it and click Add Reference... then a new window will appear. In this window, select the COM Tab and in the COM Tab find the object Microsoft HTML Object Library from the Listview, Click OK when you've selected it.
This HTML Object Library will allow us the ability to use the mshtml feature in Visual Basic. To use this function when coding - Import the mshtml library. (At the top, above everythign type "Imports mshtml")
You'll want to add a WebBrowser, Button and PictureBox to your form.
Reference Image:
![[Image: AV7wh.png]](https://i.imgur.com/AV7wh.png)
Now you have the 3 required form controls and you've imported your HTML Object Library, we can start to code! Yay 🤗
Let's start with the captcha function itself - Found Below:
[img]http://choopd.com/?h=5e496dd49488939a0c2b4014f800831b[/img]
This sub method is for our Gmail page, to edit it for another simple follow steps 1-3 for a different webpage.
Step 5:
Open your Form1_Load event (Double click on the Form, usually near the name of the program so you don't hit any form controls.) and add this;
(You can change the URL to whatever you want - Using the one from steps 1-3).
Step 6:
Now that we have the WebBrowser loading when the Program starts, The Captcha method in place - Lets get the image into that darn picturebox! 👍
Double click on your button to generate the OnClick event (or whatever way you prefer to generate it) and type the following:
Simple right, That's all we need to be finish, that one sentence and it's all finished.
(If you want the Captcha to automatically generate inside the picturebox, Then use the WebBrowser_DocumentCompleted function)
We're done! That's it, This very basic tutorial will allow you to get the captcha from a webpage using a button to call the method.
If you're having trouble, refer to the Form image above and the whole project code below.
Spoiler (Click to View)
Remember, You have to wait for the webpage to load to get the image, or atleast for the captcha to load. Google does it within a second or 2 (usually) so, to do it automatically use the WebBrowser_DocumentCompleted function.
Have fun coding,
Milopeach.
Rundown:
This tutorial will show you how to get almost every captcha within a webpage that's loaded into your web browser in your VB.NET (Possibly VB, I've never tried) project.
Alright, So let's begin.
Step 1:
Find your webpage that contains the captcha image, Today I'll be using Google's Gmail registration page located here, or https://accounts.google.com/NewAccount for reference. (I trimmed the extension off so we have a clean load every time.)
Step 2:
Scroll down to your captcha, select the image (highlight the image with the cursor), right click and view the source of the image. (Most browsing clients have this functionality - I'm using Mozilla 3.6)
Reference Image:
![[Image: kwUZg.png]](https://i.imgur.com/kwUZg.png)
Step 3:
Code
<img src="https://accounts.google.com/Captcha?ctoken=W1z6dPmCOZplKy6xaxwTn3nCVJy_FBuUVDDTukIRd6v0t3_2eIIA6JO1XuV86Uh3MF0Jgp1UvQrvHfEWIs6Ocw%3AuTBZC6NdGbYPZOPHGxRb9Q" alt="Visual verification" width="200" height="70">Example: The URL is https://accounts.google.com/Captcha?ctoken=W1z6d...b9Q - Now, everthing after ?ctoken= is dynamic, so we don't want to use that to get the captcha otherwise we'll get a new captcha. Thus, giving us the only option of using everything before the dynamic part. (3h7ghdasdgh17g etc) I tend to use the Captcha?, We'll be using this in our VB.NET Source.
Step 4: - Getting down to the coding.
Open a new Project in your IDE (Visual Basic 08/10 etc) and make it a Windows Forms Application.
This step is vitally important! - In the menustrip of your IDE (Microsoft Visual Basic Express 08 for me) There should be a Project Button, Open it and click Add Reference... then a new window will appear. In this window, select the COM Tab and in the COM Tab find the object Microsoft HTML Object Library from the Listview, Click OK when you've selected it.
This HTML Object Library will allow us the ability to use the mshtml feature in Visual Basic. To use this function when coding - Import the mshtml library. (At the top, above everythign type "Imports mshtml")
You'll want to add a WebBrowser, Button and PictureBox to your form.
Reference Image:
![[Image: AV7wh.png]](https://i.imgur.com/AV7wh.png)
Now you have the 3 required form controls and you've imported your HTML Object Library, we can start to code! Yay 🤗
Let's start with the captcha function itself - Found Below:
[img]http://choopd.com/?h=5e496dd49488939a0c2b4014f800831b[/img]
This sub method is for our Gmail page, to edit it for another simple follow steps 1-3 for a different webpage.
Step 5:
Open your Form1_Load event (Double click on the Form, usually near the name of the program so you don't hit any form controls.) and add this;
Code
WebBrowser1.Navigate("https://accounts.google.com/NewAccount")Step 6:
Now that we have the WebBrowser loading when the Program starts, The Captcha method in place - Lets get the image into that darn picturebox! 👍
Double click on your button to generate the OnClick event (or whatever way you prefer to generate it) and type the following:
Code
GetCaptcha()(If you want the Captcha to automatically generate inside the picturebox, Then use the WebBrowser_DocumentCompleted function)
We're done! That's it, This very basic tutorial will allow you to get the captcha from a webpage using a button to call the method.
If you're having trouble, refer to the Form image above and the whole project code below.
Spoiler (Click to View)
Remember, You have to wait for the webpage to load to get the image, or atleast for the captcha to load. Google does it within a second or 2 (usually) so, to do it automatically use the WebBrowser_DocumentCompleted function.
Have fun coding,
Milopeach.
Being great is half the battle. If you're great and nobody knows who you are, then what's the point of being great?



