Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import the required libraries
- using OpenQA.Selenium;
- using OpenQA.Selenium.Chrome;
- using TwoCaptcha.Captcha;
- namespace TwoCaptcha
- {
- public class Scraper
- {
- static void Main(string[] args)
- {
- // set up ChromeDriver
- IWebDriver driver = new ChromeDriver();
- // navigate to the target url
- string target_url = "https://www.google.com/recaptcha/api2/demo";
- driver.Navigate().GoToUrl(target_url);
- // create a new TwoCaptcha instance
- TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
- // create a new instance of the ReCaptcha class
- ReCaptcha captcha = new ReCaptcha();
- // set the site key for the ReCaptcha
- captcha.SetSiteKey("6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-");
- // set the URL of the target webpage where the ReCaptcha is located
- captcha.SetUrl(target_url);
- // declare solution variable
- string solution = null;
- try
- {
- // call the Solve method to solve the ReCaptcha
- solver.Solve(captcha).Wait();
- solution = captcha.Code;
- // print the captcha solution
- Console.WriteLine("Captcha solved: " + solution);
- }
- catch (AggregateException e)
- {
- // if an error occurs during captcha solving, catch the AggregateException and print the error message
- Console.WriteLine("Error occurred: " + e.InnerExceptions.First().Message);
- }
- // select g-recaptcha-response element
- IWebElement recaptchaResponseElement = driver.FindElement(By.Id("g-recaptcha-response"));
- // set the value of selected element to the CAPTCHA solution
- ((IJavaScriptExecutor)driver).ExecuteScript($"arguments[0].value = '{solution}';", recaptchaResponseElement);
- // click the submit button
- IWebElement submitButton = driver.FindElement(By.CssSelector("#recaptcha-demo-submit"));
- submitButton.Click();
- // take a screenshot
- ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile("screenshot.png");
- // close the browser
- driver.Quit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement