internal bool Send(Func <object> action) { if (_tokenSource.IsCancellationRequested) { return(false); } var eoAction = new EO.Base.ActionWithResult(action); bool isSignaled; lock (_lock) { _threadRunner.Send(eoAction, EoLargeTimeout, out isSignaled); } return(isSignaled); }
private async Task <bool> Continue(bool success) { string fameNameScript = $"document.querySelector('{reCaptchaFrameSelector}').name"; success = EvaluateScriptWithResult(fameNameScript, out string frameName); //TODO Not Work string removeDisabledAttr = $"document.querySelector('{continueButtonSelector}').removeAttribute('disabled')"; success = success && EvaluateScript(removeDisabledAttr); string removeDisabledClass = $"document.querySelector('{continueButtonSelector}').classList.remove('tw-button--disabled')"; success = success && EvaluateScript(removeDisabledClass); string focusScript = $"document.querySelector('{continueButtonSelector}').focus()"; await Task.Delay(500); threadRunner.Send(() => { webView.SendKeyEvent(true, KeyCode.Enter); }); return(success); }
/// <summary> /// download HTML as an asynchronous operation. /// </summary> /// <param name="siteUrl">The URL.</param> /// <param name="sitePageType">Type of the page.</param> /// <param name="siteSignature">The siteSignature.</param> /// <param name="proxy">The proxy.</param> /// <returns>Task<System.Boolean>.</returns> public (string html, bool isSuccessful) DownloadHtml(string siteUrl, PageType sitePageType, string siteSignature, WebProxy proxy) { var taskDone = false; string html = null; var isSuccessful = false; var isUsingProxy = false; string instanceHash; // Attach proxy if (proxy != null) { isUsingProxy = true; } // Generate SHA256 for thread name/ Web Instance using (var sha256Hash = SHA256.Create()) { instanceHash = HashGenerator.GetCryptographicHash(sha256Hash, siteUrl); } // Setup EO WebEngine var newWebEngine = Engine.Create(instanceHash); newWebEngine.Options.AllowProprietaryMediaFormats(); newWebEngine.Options.DisableGPU = true; var options = new BrowserOptions { AllowJavaScriptOpenWindow = false, LoadImages = false }; newWebEngine.Options.SetDefaultBrowserOptions(options); newWebEngine.Options.ExtraCommandLineArgs = "--mute-audio"; if (isUsingProxy) { newWebEngine.Options.Proxy = new ProxyInfo(ProxyType.HTTP, proxy.Address.Host, proxy.Address.Port); } // Instantiate thread runner var runner = new ThreadRunner(instanceHash, newWebEngine); var view = runner.CreateWebView(); // Handle certificate error view.CertificateError += (sender, e) => { e.Continue(); }; // User Agent view.CustomUserAgent = RequesterDefaults.UserAgent; runner.Send(async() => { var task = view.LoadUrl(siteUrl); task.WaitOne(20000); string googleRedirectorCyberlockerValue = null; // Custom Handler to check redirect location response header task.WebView.AfterReceiveHeaders += (sender, e) => { if (string.IsNullOrWhiteSpace(e.Response.RedirectLocation) || !e.Response.RedirectLocation.Contains("googlevideo.com")) { return; } googleRedirectorCyberlockerValue = e.Response.RedirectLocation; }; switch (sitePageType) { case PageType.Static: break; case PageType.Javascript: await Task.Delay(RequesterDefaults.JavascriptPageWait); break; case PageType.Cloudflare: await Task.Delay(RequesterDefaults.CloudflarePageWait); break; default: throw new ArgumentOutOfRangeException(typeof(PageType).ToString()); } if (view.CanEvalScript) { html = task.WebView.GetHtml(); if (html.Contains(siteSignature)) { isSuccessful = true; } } // Replace In=Site URL with Google Redirector URL var doc = new HtmlDocument(); doc.LoadHtml(html); var googleRedirectorCyberlockerNode = doc.DocumentNode.SelectSingleNode("//video[@id='my_video_1_html5_api']"); if (googleRedirectorCyberlockerNode != null) { doc.DocumentNode.SelectSingleNode("//video[@id='my_video_1_html5_api']") .SetAttributeValue("src", googleRedirectorCyberlockerValue); } if (!string.IsNullOrWhiteSpace(doc.DocumentNode.InnerHtml)) { html = doc.DocumentNode.InnerHtml; } taskDone = true; }, 60000); while (!taskDone) { Thread.Sleep(2000); } view.Destroy(); newWebEngine.Stop(true); runner.Dispose(); return(html, isSuccessful); }
private void Load_URL() { try { button_loading.Invoke((MethodInvoker) delegate { button_loading.Enabled = false; }); button1.Invoke((MethodInvoker) delegate { button1.Enabled = false; }); //Create a ThreadRunner object ThreadRunner threadRunner = new ThreadRunner(); //Create a WebView through the ThreadRunner WebView webView = threadRunner.CreateWebView(); threadRunner.Send(() => { webView.LoadUrlAndWait("https://www.myscore.ru/"); webView.Capture(); }); webView.EvalScript("" + Properties.Resources.api.Clone()); System.Threading.Thread.Sleep(300); for (int i = 0; i < (int)webView.EvalScript("$('div[class *=\"tabs__text tabs__text--default\"]').length;"); i++) { if ((string)webView.EvalScript("$('div[class *=\"tabs__text tabs__text--default\"]')[" + i + "].innerText;") == "Коэффициенты") { webView.EvalScript("$('div[class *=\"tabs__text tabs__text--default\"]')[" + i + "].click();"); System.Threading.Thread.Sleep(300); if (checkBox1.Checked && load_date.Value != DateTime.Today) { TimeSpan timeSpan = load_date.Value - DateTime.Today; if (timeSpan.Days > 7 || timeSpan.Days < -7) { MessageBox.Show("На сайте нет ифнормации за это число!", "Неверная дата", MessageBoxButtons.OK, MessageBoxIcon.Warning); button_loading.Invoke((MethodInvoker) delegate { button_loading.Enabled = true; }); button1.Invoke((MethodInvoker) delegate { button1.Enabled = true; }); return; } webView.EvalScript("$('div[class *=\"calendar__datepicker\"]').click();"); System.Threading.Thread.Sleep(300); for (int k = 0; k < 15; k++) { if (((string)webView.EvalScript("$('div[class *=\"calendar__datepicker--dates\"] > div.day')[" + k + "].innerText")).Contains(load_date.Value.ToString("dd") + "/" + load_date.Value.ToString("MM"))) { webView.EvalScript("$('div[class *=\"calendar__datepicker--dates\"] > div.day')[" + k + "].click();"); System.Threading.Thread.Sleep(300); break; } } } webView.EvalScript("$('div[class *=\"event__expander icon--expander expand\"]').click();"); System.Threading.Thread.Sleep(100); int leght_j = (int)webView.EvalScript("$('div[class *=\"event__match event__match\"]').length"); for (int j = 0; j < leght_j; j++) { System.Data.DataRow data = save_resDataSet.Table.NewRow(); data["Название"] = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[2].innerText") + " - " + (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[3].innerText"); if (checkBox1.Checked) { data["Дата"] = load_date.Value; } else { data["Дата"] = DateTime.Today; } string temp_str = "NULL"; if ((string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[4].innerText") == "-") { temp_str = " - "; } else { int temp_1 = (int)webView.EvalScript("parseInt($('div[class *=\"event__match event__match\"]')[" + j + "].children[4].children[0].innerText)"); int temp_2 = (int)webView.EvalScript("parseInt($('div[class *=\"event__match event__match\"]')[" + j + "].children[4].children[1].innerText)"); if (temp_1 == temp_2) { temp_str = "Ничья"; } else if (temp_2 > temp_1) { temp_str = "Победила вторая команда"; } else { temp_str = "Победила первая команда"; } } data["Результат"] = temp_str; string temp1_1; string temp1_2; string temp1_3; if ((string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[5].innerText") == "-") { temp1_1 = " - "; } else { temp1_1 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[5].children[0].getAttribute('alt')"); if (temp1_1.LastIndexOf('[') != -1) { temp1_1 = temp1_1.Substring(0, temp1_1.LastIndexOf('[')); } else if (temp1_1 == "Букмекер больше не принимает ставку.") { temp1_1 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[5].children[0].innerText"); } } if ((string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[6].innerText") == "-") { temp1_2 = " - "; } else { temp1_2 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[6].children[0].getAttribute('alt')"); if (temp1_2.LastIndexOf('[') != -1) { temp1_2 = temp1_2.Substring(0, temp1_2.LastIndexOf('[')); } else if (temp1_2 == "Букмекер больше не принимает ставку.") { temp1_2 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[6].children[0].innerText"); } } if ((string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[7].innerText") == "-") { temp1_3 = " - "; } else { temp1_3 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[7].children[0].getAttribute('alt')"); if (temp1_3.LastIndexOf('[') != -1) { temp1_3 = temp1_3.Substring(0, temp1_3.LastIndexOf('[')); } else if (temp1_3 == "Букмекер больше не принимает ставку.") { temp1_3 = (string)webView.EvalScript("$('div[class *=\"event__match event__match\"]')[" + j + "].children[7].children[0].innerText"); } } data["Коэффициент"] = temp1_1 + " : " + temp1_2 + " : " + temp1_3; if (temp_str == " - " && temp1_1 == " - " && temp1_2 == " - " && temp1_3 == " - ") { continue; } if (save_resDataSet.Table.Select("Результат = '" + data["Результат"] + "' AND Название = '" + data["Название"] + "' AND Коэффициент = '" + data["Коэффициент"] + "'").Length <= 0) { save_resDataSet.Table.Rows.Add(data); } } button_loading.Invoke((MethodInvoker) delegate { button_loading.Enabled = true; }); button1.Invoke((MethodInvoker) delegate { button1.Enabled = true; }); break; } } } catch (Exception e) { MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } }
/// <summary> /// download HTML as an asynchronous operation. /// </summary> /// <param name="siteUrl">The URL.</param> /// <param name="sitePageType">Type of the page.</param> /// <param name="siteSignature">The siteSignature.</param> /// <param name="proxy">The proxy.</param> /// <returns>Task<System.Boolean>.</returns> public (string html, bool isSuccessful) DownloadHtml(string siteUrl, PageType sitePageType, string siteSignature, WebProxy proxy) { var taskDone = false; string html = null; var isSuccessful = false; var isUsingProxy = false; string instanceHash; // Attach proxy if (proxy != null) { isUsingProxy = true; } // Generate SHA256 for thread name/ Web Instance using (var sha256Hash = SHA256.Create()) { instanceHash = HashGenerator.GetCryptographicHash(sha256Hash, siteUrl); } // Setup EO WebEngine var newWebEngine = Engine.Create(instanceHash); newWebEngine.Options.AllowProprietaryMediaFormats(); newWebEngine.Options.DisableGPU = true; var options = new BrowserOptions { AllowJavaScriptOpenWindow = false, LoadImages = false }; newWebEngine.Options.SetDefaultBrowserOptions(options); newWebEngine.Options.ExtraCommandLineArgs = "--mute-audio"; if (isUsingProxy) { newWebEngine.Options.Proxy = new ProxyInfo(ProxyType.HTTP, proxy.Address.Host, proxy.Address.Port); } // Instantiate thread runner var runner = new ThreadRunner(instanceHash, newWebEngine); var view = runner.CreateWebView(); // Handle certificate error view.CertificateError += (sender, e) => { e.Continue(); }; view.CustomUserAgent = RequesterDefaults.UserAgent; runner.Send(async() => { var task = view.LoadUrl(siteUrl); task.WaitOne(20000); switch (sitePageType) { case PageType.Static: break; case PageType.Javascript: await Task.Delay(RequesterDefaults.JavascriptPageWait); break; case PageType.Cloudflare: await Task.Delay(RequesterDefaults.CloudflarePageWait); break; default: throw new ArgumentOutOfRangeException(typeof(PageType).ToString()); } if (view.CanEvalScript) { html = task.WebView.GetHtml(); if (html.Contains(siteSignature)) { isSuccessful = true; } } taskDone = true; }); while (!taskDone) { Thread.Sleep(2000); } view.Destroy(); newWebEngine.Stop(true); runner.Dispose(); return(html, isSuccessful); }