示例#1
0
        /// <summary>
        /// enters phrase in a way depending on clickerInput
        /// </summary>
        /// <param name="clickerInput">bool if clicker enabled</param>
        /// <param name="webBrowser">cafsharp browser interface</param>
        /// <param name="phrase">built search phrase</param>
        public async Task EnterPhraseAsync(bool clickerInput, IWpfWebBrowser webBrowser, string phrase)
        {
            _log.Called(clickerInput, string.Empty, phrase);

            try
            {
                if (!clickerInput)
                {
                    phrase = ValidatePhrase(phrase);

                    await webBrowser.EvaluateScriptAsync(@"
                           var arr = document.getElementsByTagName('input')[2].value = '" + phrase + @"';
                           ");
                }
                else
                {
                    await _inputService.ClickSearchBarInputAsync();

                    await _inputService.EnterPhraseInputAsync(phrase);
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
            }
        }
示例#2
0
        private async void GetInnerHTML()
        {
            try
            {
                var response = await webBrowser.EvaluateScriptAsync("myBytes=window.document.body.innerHTML;");

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                MainWindow.strInnerHtml = (string)(response.Success ? (response.Result ?? "null") : response.Message);
                ParseHtmlHelper m_ParseHtmlHelper = new ParseHtmlHelper((string)MainWindow.strInnerHtml);
                m_ParseHtmlHelper.GetMessageUrl();

                for (int i = 0; i < m_ParseHtmlHelper.MessageUrlMatchs.Count; i++)
                {
                    string m_Message = m_ParseHtmlHelper.MessageUrlMatchs[i].Groups[1].Captures[0].Value;  /* need handle */
                    string ifrm_name = string.Format(@"frm{0}", i);
                    string JsCmd     = "document.body.insertAdjacentHTML(\"beforeEnd\", \"<iframe width='400' height='50' id='" + ifrm_name + "' src='" + m_Message + "'/>\");";
                    response = await webBrowser.EvaluateScriptAsync(JsCmd);

                    Random ran     = new Random(); /* 搞个随机数防检测 */
                    int    RandKey = ran.Next(200, 1500);
                    Thread.Sleep(RandKey);
                    JsCmd    = "var iFrame = document.getElementById('" + ifrm_name + "');var iFrameElement = iFrame.contentWindow.document.body.innerHTML;MyByte=iFrameElement;";
                    response = await webBrowser.EvaluateScriptAsync(JsCmd);

                    MainWindow.strMessageHtml += (string)(response.Success ? (response.Result ?? "null") : response.Message);
                }

                response = await webBrowser.EvaluateScriptAsync("myBytes=window.document.body.innerHTML;");

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                MainWindow.strInnerHtml = (string)(response.Success ? (response.Result ?? "null") : response.Message);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#3
0
        private void BrowserOnFrameLoadEnd(object _, FrameLoadEndEventArgs __)
        {
            Script.Initialize(_webBrowser.ExecuteScriptAsync, s => _webBrowser.EvaluateScriptAsync(s));

//      var map = new Map( "map" )
//        .SetView( new LatLng( 47.6097, -122.3331 ) )
//        .AddTileLayer( @"http://{s}.tile.osm.org/{z}/{x}/{y}.png" );
//
//      var marker = new Marker( new LatLng( 47.6097, -122.3331 ) );
//      marker.AddTo( map );
        }
示例#4
0
        private async void EvaluateJavaScript(string s)
        {
            try
            {
                var response = await webBrowser.EvaluateScriptAsync(s);

                EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#5
0
        private async void EvaluateJavaScript(string s)
        {
            try
            {
                var response = await webBrowser.EvaluateScriptAsync(s);

                if (response.Success && response.Result is IJavascriptCallback)
                {
                    response = await((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript");
                }

                EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#6
0
        /// <summary>
        /// clicks html document object in a way depending on clickerInput
        /// </summary>
        /// <param name="clickerInput">bool if clicker enabled</param>
        /// <param name="webBrowser">cefsharp browser interface</param>
        public async Task ClickSearchBtnAsync(bool clickerInput, IWpfWebBrowser webBrowser)
        {
            _log.Called(clickerInput, string.Empty);

            try
            {
                if (!clickerInput)
                {
                    await webBrowser.EvaluateScriptAsync(@"
                           var arr = document.getElementsByTagName('input')[3].click();
                           ");
                }
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
            }
        }
        private void EvaluateJavaScript(string s)
        {
            try
            {
                var task = webBrowser.EvaluateScriptAsync(s);

                task.ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        var response             = t.Result;
                        EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
                    }
                },
                                  TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception e)
            {
                MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#8
0
        /// <summary>
        /// checks if in the html document is captcha
        /// </summary>
        /// <param name="webBrowser">cefsharp browser interface</param>
        public async Task <bool> CheckForRecaptchaAsync(IWpfWebBrowser webBrowser)
        {
            _log.Called(string.Empty);

            try
            {
                bool isCaptcha = false;

                Task <JavascriptResponse> verifyReCaptcha = webBrowser.EvaluateScriptAsync(@"
			(function() {
				const arr = document.getElementsByTagName('a');
				for (i = 0; i < arr.length; ++i) {
					item = arr[i];
					if (document.getElementById('infoDiv'))
						{ return true; }
					}
				}
			)();"            );

                await verifyReCaptcha.ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        var response = t.Result;
                        var EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
                        isCaptcha = Convert.ToBoolean(response.Result);
                    }
                }
                                                   );

                return(isCaptcha);
            }
            catch (Exception e)
            {
                _log.Error(e.Message);

                return(true);
            }
        }
示例#9
0
        /// <summary>
        /// searches for URL data in html document
        /// </summary>
        /// <param name="webBrowser">cefsharp browser interface</param>
        /// <returns>string tag data</returns>
        public async Task <string> GetUrlAsync(IWpfWebBrowser webBrowser)
        {
            _log.Called(string.Empty);

            try
            {
                string url = "";

                Task <JavascriptResponse> findUrl = webBrowser.EvaluateScriptAsync(@"
			(function() {
				var results = document.getElementsByClassName('srg')[0];
                    var result = results.getElementsByClassName('g')[0];
                    var div = result.getElementsByTagName('div')[0];
                    return div.innerHTML;
				}
			)();"            );

                await findUrl.ContinueWith(t =>
                {
                    if (!t.IsFaulted)
                    {
                        var response = t.Result;
                        var EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
                        url = Convert.ToString(response.Result);
                    }
                }
                                           );

                url = SplitUrl(url);

                return(url);
            }
            catch (Exception e)
            {
                _log.Error(e.Message);

                return(string.Empty);
            }
        }
示例#10
0
        /// <summary>
        /// switches off JS alerts
        /// </summary>
        /// <param name="webBrowser">cefsharp browser interface</param>
        public async Task TurnOffAlertsAsync(IWpfWebBrowser webBrowser)
        {
            await webBrowser.EvaluateScriptAsync(@"
			window.alert = function(){}
			"            );
        }