Recently I published an article on how to solve captcha in C# using DeathByCaptcha service, and I promised to offer you an example in other languages as well. In this post I’ll offer a Java project that does the same thing.

1. Opening the Webpage

First we need to initialize the WebDriver and open the target webpage. Let’s use the Firefox driver for this:

Java

1

2

3

FirefoxDriver driver=newFirefoxDriver();

driver.manage().timeouts().implicitlyWait(1,TimeUnit.SECONDS);

driver.navigate().to("http://testing-ground.scraping.pro/captcha");

2. Getting the Captcha Image

To get the image we will take a screenshot of the whole screen and then cut the image out according to its dimensions and location. After that the image is saved into a file in PNG format for further sending to DeathByCaptcha service:

You may ask why I use such a complicated solution in taking a screenshot and extracting the image from it. Why not download the ready image by its URL? The problem is that every time you request the image the server returns a new, randomly generated CAPTCHA, so to enter a valid code you need to use the very image that was generated specifically for the page on which you enter the code.

3. Requesting the DeathByCaptcha Service

Now as we have the captcha image extracted, we can send it to DeathByCaptcha for recognition. It’s done in a couple of code lines:

Java

1

2

SocketClient client=newSocketClient("user","password");

Captcha res=client.decode(newByteArrayInputStream(os.toByteArray()));

Note that you need to replace “user” and “password” with your real DeathByCaptcha account details.

4. Typing the Recognized Captcha In

As soon as we get the response from DeathByCaptcha, we can type it into the page accessing the secure part:

we develop a software in vb.net/c#, for extract data from website. where website added capicha characters to receive detailed data, and through our software we have to enter capicha character one by one. can you help us to read capitcha image.
thanks