private async void CefSharp_DocumentComplete(object sender, LoadingStateChangedEventArgs e) { bool isSetCaptchaResponse = false; bool isSubmitButtonClicked = false; string UrlText = webBrowser.Address == null ? string.Empty : webBrowser.Address.ToString(); documentSource = await webBrowser.GetBrowser().MainFrame.GetSourceAsync(); htmlAgilityDocument = new HtmlAgilityPack.HtmlDocument(); htmlAgilityDocument.LoadHtml(documentSource); if (await checkIDElementExists("recaptcha-demo")) { string googleKey = GetGoogleRecaptchaKey(documentSource); string captchaKey = "84e20a36e9857a0b7bc129ab69f1b043"; if (!string.IsNullOrEmpty(googleKey)) { CaptchaResponse capResponse = start2captchaSolver(googleKey, captchaKey); if (capResponse.status == 1 && !string.IsNullOrEmpty(capResponse.request)) { await setIDElementInnerHTML("g-recaptcha-response", capResponse.request); await AsyncDelay(3000); await clickIDElement("recaptcha-demo-submit"); await AsyncDelay(3000); documentSource = await webBrowser.GetBrowser().MainFrame.GetSourceAsync(); System.Threading.Thread.Sleep(3000); htmlAgilityDocument.LoadHtml(documentSource); if (await checkIDElementExists("application_number_radiobutton")) { await clickIDElement("application_number_radiobutton"); await AsyncDelay(1000); if (await checkIDElementExists("number_id")) { } } } } //var loadingNodes = htmlAgilityDocument.DocumentNode.SelectNodes("//div[contains(@id, 'recaptcha-demo')]"); } //var loadingNodes = htmlAgilityDocument.DocumentNode.SelectNodes("//div[contains(@id, 'recaptcha-demo')]"); //HtmlAgilityPack.HtmlNodeCollection tagCollection = htmlAgilityDocument.DocumentNode.SelectNodes("//div"); if (!e.IsLoading && !loginProcessInitiated) { try { } catch (Exception ex) { } } }
private CaptchaResponse start2captchaSolver(string googlekey, string captchakey) { try { string rt; int counter = 0; CaptchaResponse finresponse = null; WebRequest request = WebRequest.Create("http://2captcha.com/in.php?key=" + captchakey + "&method=userrecaptcha&googlekey=" + googlekey + "&pageurl=https://portal.uspto.gov/pair/PublicPair/&here=now&json=1"); WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); rt = reader.ReadToEnd(); CaptchaResponse cresponse = new JavaScriptSerializer().Deserialize <CaptchaResponse>(rt); if (cresponse != null && cresponse.status == 1) { while (true) { if (counter == 15) { CaptchaResponse error = new CaptchaResponse(); error.status = -1; error.request = "Error"; return(error); } WebRequest reponse = WebRequest.Create("http://2captcha.com/res.php?key=" + captchakey + "&action=get&id=" + cresponse.request + "&json=1"); WebResponse result = reponse.GetResponse(); Stream dataStream1 = result.GetResponseStream(); StreamReader reader1 = new StreamReader(dataStream1); rt = reader1.ReadToEnd(); finresponse = new JavaScriptSerializer().Deserialize <CaptchaResponse>(rt); if (finresponse != null && finresponse.status == 1) { return(finresponse); } else { System.Threading.Thread.Sleep(3000); counter++; } } } return(finresponse); } catch (Exception ex) { throw; } }