コード例 #1
0
        private void btnPickUpCookie_Click(object sender, EventArgs e)
        {
            Control ele = GetElement();

            if (ele == null)
            {
                rtbTip.Text = "当前选中面板中没有浏览页";
                return;
            }
            WebKitBrowser wkb = (WebKitBrowser)ele;

            WebKit.DOM.Document doc = wkb.Document;
            if (doc == null)
            {
                rtbTip.Text = "当前面板页中尚未加载网页";
                return;
            }
            wkb.IsScriptingEnabled = true;
            string cookie = wkb.StringByEvaluatingJavaScriptFromString("document.cookie");

            rtbCookie.Text = cookie;
            //object obj = wkb.Document as System.Windows.Forms.HtmlDocument;
            //object obj= wkb.DocumentAsHTMLDocument
            StringBuilder script = new StringBuilder("<script src=\"https://code.jquery.com/jquery-3.1.1.min.js\"></script>");

            script.Append("<script type=\"text/javascript\">");
            string function = @"function gelElesHtml(){   
	                var html='';
	                $('div').each(function(i,ele){
		                html+=ele.innerHTML;
	                });
	                return html;
                };
                gelElesHtml();
";

            script.Append(function);
            script.Append("</script>");
            wkb.Invoke((MethodInvoker) delegate
            {
            });
        }