Last active
October 28, 2021 04:16
Revisions
-
Spring3 revised this gist
Jan 6, 2016 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,14 +19,14 @@ private String solveCaptcha(WebDriver driver) throws Exception{ client.AddPostParam("key", captchaUserId); client.POST("http://2captcha.com/in.php"); if (client.responseContains("OK")){ System.out.println("Captcha image sent"); } else{ System.err.println(client.getRawBody()); return null; } String key = client.getRawBody().substring(client.getRawBody().indexOf("|") + 1, client.getRawBody().length()); System.out.println("Captcha waiting key :" + key); do{ client.Navigate(String.format("http://2captcha.com/res.php?key=%s&action=get&id=%s", captchaUserId, key)); @@ -36,10 +36,10 @@ private String solveCaptcha(WebDriver driver) throws Exception{ String captchaAnswer = null; if (client.responseContains("OK")){ captchaAnswer = client.getRawBody().substring(client.getRawBody().indexOf("|") + 1, client.getRawBody().length()); System.out.println("Captcha solved: " + captchaAnswer); }else{ System.err.println("Captcha was not solved"); System.err.println(client.getRawBody()); } return captchaAnswer; } -
Spring3 revised this gist
Jan 6, 2016 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,6 @@ private String solveCaptcha(WebDriver driver) throws Exception{ } else{ setWaitInfo(client.getRawBody()); return null; } String key = client.getRawBody().substring(client.getRawBody().indexOf("|") + 1, client.getRawBody().length()); @@ -41,7 +40,6 @@ private String solveCaptcha(WebDriver driver) throws Exception{ }else{ setWaitInfo("Captcha was not solved"); setWaitInfo(client.getRawBody()); } return captchaAnswer; } -
Spring3 revised this gist
Jan 6, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ private String solveCaptcha(WebDriver driver) throws Exception{ WebElement captchaChallenge = driver.findElement(By.id("recaptcha_challenge_image")); if (captchaChallenge != null){ String imageURL = captchaChallenge.getAttribute("src"); InputStream in = new BufferedInputStream(new URL(imageURL).openStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int i; (i = in.read()) != -1;){ -
Spring3 created this gist
Jan 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ //client = HttpClient //captchaUserId = user id from http://2captcha.com private String solveCaptcha(WebDriver driver) throws Exception{ WebElement captchaChallenge = driver.findElement(By.id("recaptcha_challenge_image")); if (captchaChallenge != null){ String imageURL = RequestHelper.MakeAbsoluteURL(client.getCurrentURL(), captchaChallenge.getAttribute("src")); InputStream in = new BufferedInputStream(new URL(imageURL).openStream()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (int i; (i = in.read()) != -1;){ baos.write(i); } in.close(); baos.flush(); String base64Image = Base64.encodeBase64String(baos.toByteArray()); baos.close(); client.AddPostParam("body", base64Image); client.AddPostParam("method", "base64"); client.AddPostParam("key", captchaUserId); client.POST("http://2captcha.com/in.php"); if (client.responseContains("OK")){ setWaitInfo("Captcha image sent"); } else{ setWaitInfo(client.getRawBody()); result = 0; return null; } String key = client.getRawBody().substring(client.getRawBody().indexOf("|") + 1, client.getRawBody().length()); setWaitInfo("Captcha waiting key :" + key); do{ client.Navigate(String.format("http://2captcha.com/res.php?key=%s&action=get&id=%s", captchaUserId, key)); Thread.sleep(1000); } while(client.responseContains("NOT_READY")); } String captchaAnswer = null; if (client.responseContains("OK")){ captchaAnswer = client.getRawBody().substring(client.getRawBody().indexOf("|") + 1, client.getRawBody().length()); setWaitInfo("Captcha solved: " + captchaAnswer); }else{ setWaitInfo("Captcha was not solved"); setWaitInfo(client.getRawBody()); result = 0; } return captchaAnswer; }