您好,我正在尝试在这里自动化一些过程。 我正在使用2captch来解决验证码,请查看图片。
我得到了site_key和api_key,现在我正在发送api_key + site_key并且它正在返回我response_token,我已经将返回的响应令牌添加到g-recaptcha-response
中,但它没有提交表单。
我想要的是:我可以解决验证码并提交表格。
这是我当前的Java代码:
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
ChromeDriver driver;
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("https://id.sonyentertainmentnetwork.com/signin/?client_id=fe1fdbfa-f1a1-47ac-b793-e648fba25e86&redirect_uri=https://secure.eu.playstation.com/psnauth/PSNOAUTHResponse/pdc/&service_entity=urn:service-entity:psn&response_type=code&scope=psn:s2s&ui=pr&service_logo=ps&request_locale=en_GB&error=login_required&error_code=4165&error_description=User+is+not+authenticated&no_captcha=false#/signin?entry=%2Fsignin");
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@title='Sign-In ID (Email Address)']")).sendKeys("email");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@title='Password']")).sendKeys("password");
Thread.sleep(2000);
driver.findElement(By.xpath("//button[@class='primary-button row-button text-button touch-feedback']")).click();
Thread.sleep(3000);
By captcha = By.xpath("//iframe[@title='recaptcha challenge']");
String src = driver.findElement(captcha).getAttribute("src");
String key = getKey(src);
System.out.println(key);
String apiKey = "API_KEY";
String googleKey = key;
String pageUrl = "https://id.sonyentertainmentnetwork.com/signin/?client_id=fe1fdbfa-f1a1-47ac-b793-e648fba25e86&redirect_uri=https://secure.eu.playstation.com/psnauth/PSNOAUTHResponse/pdc/&service_entity=urn:service-entity:psn&response_type=code&scope=psn:s2s&ui=pr&service_logo=ps&request_locale=en_GB&error=login_required&error_code=4165&error_description=User+is+not+authenticated&no_captcha=false#/signin?entry=%2Fsignin";
String proxyIp = "183.38.231.131";
String proxyPort = "8888";
String proxyUser = "username";
String proxyPw = "password";
TwoCaptchaService service = new TwoCaptchaService(apiKey, googleKey, pageUrl, proxyIp, proxyPort, proxyUser, proxyPw, ProxyType.HTTP);
try {
String responseToken = service.solveCaptcha();
System.out.println("The response token is: " + responseToken);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById("g-recaptcha-response").innerHTML = '"+responseToken+"';");
} catch (InterruptedException e) {
System.out.println("ERROR case 1");
e.printStackTrace();
} catch (IOException e) {
System.out.println("ERROR case 2");
e.printStackTrace();
}
更新的代码:
js.executeScript("document.getElementById("g-recaptcha-response").innerHTML = '" + responseToken + "';");
Thread.sleep(500);
WebElement frameElement = driver.findElement(captcha);
driver.switchTo().frame(frameElement);
js.executeScript("document.getElementById('recaptcha-verify-button').click();");
它正在单击按钮,但是,它显示Please select all matching images.
。 请查看屏幕截图
您需要做的就是像这样提交它:
js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='" + responseToken + "';");
Thread.sleep(500);
js.executeScript("document.getElementById('captcha-form').submit();");
也不要忘记检查此ID:"验证码形式",它可以有所不同
要访问元素"recaptcha-verify-button":
从 API 获得响应后;
By frame = By.xpath("//iframe[@title='recaptcha challenge']");
WebElement frameElement = driver.findElement(frame);
driver.switchTo.frame(frameElement);
然后,您可以执行脚本。最后,对于您的脚本,如果您的验证码表单是一个按钮
你
不能调用提交((;
你
可以调用 click((;
最终答案:
另请检查此内容:js.executeScript("widgetVerified('TOKEN');");
要查找名为widgetVerified()
的函数,请在控制台中运行此代码。
___grecaptcha_cfg.clients[0]
这将返回一个 JSON,在该 JSON 内部尝试在@Awais的情况下找到回调函数wigdetVerified(e)
警告:不要使用任何广告拦截器