private void DownloadWebpage() { string URL = TextBox1.Text; AutoResetEvent resultEvent = new AutoResetEvent(false); string result = null; bool visible = this.Checkbox1.Checked; IEBrowser browser = new IEBrowser(visible, URL, resultEvent); // wait for the third thread getting result and setting result event EventWaitHandle.WaitAll(new AutoResetEvent[] { resultEvent }); // the result is ready later than the result event setting sometimes while (browser == null || browser.HtmlResult == null) Thread.Sleep(5); result = browser.HtmlResult; if (!visible) browser.Dispose(); //把获取的html内容通过label显示出来 Label2.Text = result; //保存结果到本程序的目录中 string path = Request.PhysicalApplicationPath; TextWriter tw = new StreamWriter(path + @"softlab/result.html"); tw.Write(result); tw.Close(); //open a new web page to display result got from webbrowser. Response.Output.WriteLine("<script>window.open ('result.html','mywindow','location=1,status=0,scrollbars=1,resizable=1,width=600,height=600');</script>"); }
public void Execute(IJobExecutionContext context) { log.Info("Comment Extractor Execution started at : " + TodDateUtils.GetCurrentTimeInIST().Date); string userID = "delltools"; string password = "******"; AutoResetEvent resultEvent = new AutoResetEvent(false); //string result = null; browser = new IEBrowser(visible, userID, password, resultEvent); //browser = new IEBrowser(visible, "delltools", "g9eDx5IWlseQEeSvknxz", resultEvent); // wait for the third thread getting result and setting result event EventWaitHandle.WaitAll(new AutoResetEvent[] { resultEvent }); // the result is ready later than the result event setting somtimes //while (browser == null || browser.HtmlResult == null) Thread.Sleep(5); //result = browser.HtmlResult; //if (!visible) browser.Dispose(); Dispose(); //throw new NotImplementedException(); log.Info("Comment Extractor Execution completed @ " + TodDateUtils.GetCurrentTimeInIST().Date); //return (Task)context.Result; }
private void DisposeAndCloseIE(bool closeIE) { if (isDisposed) { return; } Logger.LogDebug(Resources.IE_Dispose); if (closeIE && IsInternetExplorerStillAvailable()) { // Close all open HTMLDialogs HtmlDialogs.CloseAll(); } base.Dispose(true); if (closeIE && IsInternetExplorerStillAvailable()) { // Ask IE to close _ieBrowser.Quit(); } _ieBrowser = null; if (closeIE) { // Wait for IE to close to prevent RPC errors when creating // a new WatiN.Core.IE instance. Thread.Sleep(1000); } isDisposed = true; }
private void CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, bool createInNewProcess) { CheckThreadApartmentStateIsSTA(); UtilityClass.MoveMousePoinerToTopLeft(Settings.AutoMoveMousePointerToTopLeft); if (createInNewProcess) { Logger.LogAction("Creating IE instance in a new process"); _ieBrowser = CreateIEPartiallyInitializedInNewProcess(); } else { Logger.LogAction("Creating IE instance"); _ieBrowser = CreateIEBrowser(new InternetExplorerClass()); } StartDialogWatcher(); if (logonDialogHandler != null) { // remove other logon dialog handlers since only one handler // can effectively handle the logon dialog. DialogWatcher.RemoveAll(new LogonDialogHandler("a", "b")); // Add the (new) logonHandler DialogWatcher.Add(logonDialogHandler); } FinishInitialization(uri); // WaitForComplete(); }
private void cmdInstallJavascript_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser(this.webBrowser); // 定义 javascript 脚本, 声明一个 showMessage 函数. string showMessageScript = "function showMessage(message){alert('消息:' + message);}"; // 将脚本安装到 WebBrowser 中. ie.InstallScript(showMessageScript); // 执行脚本, 调用 showMessage 函数. ie.ExecuteScript("showMessage('哈哈!');"); // 定义 javascript 脚本, 声明一个 add 函数. string addScript = "function add(num1, num2){return num1 + num2;}"; // 将脚本安装到 WebBrowser 中, id 为 jsAdd. ie.InstallScript(addScript, "jsAdd"); // 执行脚本, 调用 add 函数. ie.ExecuteScript("showMessage(add(1, 3));"); // 安装本地 jquery 脚本, 需要生成目录中存在 jquery-1.5.min.js 文件. ie.InstallScript(new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"jquery-1.5.min.js"))); // 如果从网络位置载入脚本, 可以等待 5 秒钟, 以便脚本载入完毕. // ie.IEFlow.Wait ( 5 ); // 等待脚本载入完毕后, 执行一条 jquery 命令. ie.ExecuteScript("showMessage($('*').length);"); }
public FormIEBrowser() { InitializeComponent(); this.ie = new IEBrowser(this.webBrowser); this.ie.Navigate("about:blank"); }
private void cmdSub_Click(object sender, EventArgs e) { // 创建 IEBrowser 对象, 用来控制窗口的 WebBrowser 控件. IEBrowser ie = new IEBrowser(this.webBrowser); // 载入已经放在运行目录的页面 ButtonClick.htm. ie.Navigate(Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "ButtonClick.htm")); // 等待 ButtonClick.htm 完全载入. ie.IEFlow.Wait(new UrlCondition("wait", "ButtonClick.htm", StringCompareMode.EndWith)); // 根据按钮显示的文本模拟按钮点击. // 方法1: 安装搜索按钮的 javascript 函数 clickButton 来获取按钮并调用其 click 方法. // 安装 clickButton 函数. ie.InstallScript("function clickButton(text){for(var i=0;i<document.all.length;i++){if(document.all[i].value==text){document.all[i].click();break;}}}"); // 调用 clickButton 函数, 模拟点击文本为 Sub 的按钮. ie.InvokeScript("clickButton", new object[] { "Sub" }); // 方法2: 安装跟踪和 jQuery 脚本后, 执行 jQuery 来模拟点击按钮. // 安装跟踪脚本. ie.InstallTrace( ); // 安装在资源中的 jQuery 脚本. ie.InstallScript(Properties.Resources.jquery_1_5_2_min); // 执行获取按钮并模拟点击的 jQuery 脚本. ie.ExecuteJQuery(JQuery.Create("'[value=Sub]:button'").Click( )); }
private void cmdInstallJavascript_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser ( this.webBrowser ); // 定义 javascript 脚本, 声明一个 showMessage 函数. string showMessageScript = "function showMessage(message){alert('消息:' + message);}"; // 将脚本安装到 WebBrowser 中. ie.InstallScript ( showMessageScript ); // 执行脚本, 调用 showMessage 函数. ie.ExecuteScript ( "showMessage('哈哈!');" ); // 定义 javascript 脚本, 声明一个 add 函数. string addScript = "function add(num1, num2){return num1 + num2;}"; // 将脚本安装到 WebBrowser 中, id 为 jsAdd. ie.InstallScript ( addScript, "jsAdd" ); // 执行脚本, 调用 add 函数. ie.ExecuteScript ( "showMessage(add(1, 3));" ); // 安装本地 jquery 脚本, 需要生成目录中存在 jquery-1.5.min.js 文件. ie.InstallScript ( new Uri ( Path.Combine ( AppDomain.CurrentDomain.BaseDirectory, @"jquery-1.5.min.js" ) ) ); // 如果从网络位置载入脚本, 可以等待 5 秒钟, 以便脚本载入完毕. // ie.IEFlow.Wait ( 5 ); // 等待脚本载入完毕后, 执行一条 jquery 命令. ie.ExecuteScript ( "showMessage($('*').length);" ); }
public FormIEBrowser () { InitializeComponent (); this.ie = new IEBrowser ( this.webBrowser ); this.ie.Navigate ( "about:blank" ); }
public FormIEBrowserDoc( ) { InitializeComponent( ); // 从当前的 WebBrowser 控件创建 IEBrowser 对象. this.ie = new IEBrowser(this.webBrowser); }
// this is in the main thread protected void Page_Load(object sender, EventArgs e) { try { AutoResetEvent resultEvent = new AutoResetEvent(false); string result = null; bool visible = true; browser = new IEBrowser(visible, resultEvent); // wait for the third thread getting result and setting result event EventWaitHandle.WaitAll(new AutoResetEvent[] { resultEvent }); // the result is ready later than the result event setting somtimes while (browser == null || browser.HtmlResult == null) { Thread.Sleep(5); } result = browser.HtmlResult; if (!visible) { browser.Dispose(); } string path = Request.PhysicalApplicationPath; TextWriter tw = new StreamWriter(path + "result.html"); tw.Write(result); tw.Close(); Response.Output.WriteLine("<script>window.open ('result.html','mywindow','location=1,status=0,scrollbars=1,resizable=1,width=600,height=600');</script>"); } catch (Exception ex) { } }
private void cmdFlowNWPC_Click(object sender, EventArgs e) { // 定义载入 google 的页面状态. WebPageState loadGoogle = new WebPageState( "load google", // 状态的名称. completedStateSetting: new WebPageNextStateSetting("load blog", true), // 在页面完成时, 自动跳转到载入 blog 的状态. startAction: new NavigateAction("http://www.google.com.hk"), // 页面状态的开始动作为载入 http://www.google.com.hk. condition: new UrlCondition( // 判断页面状态是否完成的地址条件. "google condition", // 条件名称. "http://www.google.com.hk", // 载入的页面以 http://www.google.com.hk 开始时, 认为此地址条件成立. StringCompareMode.StartWith ) ); // 定义载入 blog 的页面状态. WebPageState loadMyBlog = new WebPageState( "load blog", // 状态的名称. startAction: new NavigateAction("http://blog.sina.com.cn/zoyobar"), // 页面状态的开始动作为载入 http://blog.sina.com.cn/zoyobar. completedAction: new ExecuteJavaScriptAction("alert('我是从 google 页面跳转过来的!');"), // 当页面状态完成后, 执行一条 javascript 脚本. condition: new UrlCondition( // 判断页面状态是否完成的地址条件. "blog condition", // 条件名称. "http://blog.sina.com.cn/zoyobar", // 载入的页面以 http://blog.sina.com.cn/zoyobar 开始时, 认为此地址条件成立. StringCompareMode.StartWith ) ); // 从当前的 WebBrowser 控件创建 IEBrowser 对象, 并赋予刚才定义的流程. IEBrowser ie = new IEBrowser(this.webBrowser, new WebPageState[] { loadGoogle, loadMyBlog }); // 从载入 google 页面的状态开始. ie.IEFlow.JumpToState("load google"); }
private void cmdSub_Click ( object sender, EventArgs e ) { // 创建 IEBrowser 对象, 用来控制窗口的 WebBrowser 控件. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 载入已经放在运行目录的页面 ButtonClick.htm. ie.Navigate ( Path.Combine ( AppDomain.CurrentDomain.BaseDirectory + "ButtonClick.htm" ) ); // 等待 ButtonClick.htm 完全载入. ie.IEFlow.Wait ( new UrlCondition ( "wait", "ButtonClick.htm", StringCompareMode.EndWith ) ); // 根据按钮显示的文本模拟按钮点击. // 方法1: 安装搜索按钮的 javascript 函数 clickButton 来获取按钮并调用其 click 方法. // 安装 clickButton 函数. ie.InstallScript ( "function clickButton(text){for(var i=0;i<document.all.length;i++){if(document.all[i].value==text){document.all[i].click();break;}}}" ); // 调用 clickButton 函数, 模拟点击文本为 Sub 的按钮. ie.InvokeScript ( "clickButton", new object[] { "Sub" } ); // 方法2: 安装跟踪和 jQuery 脚本后, 执行 jQuery 来模拟点击按钮. // 安装跟踪脚本. ie.InstallTrace ( ); // 安装在资源中的 jQuery 脚本. ie.InstallScript ( Properties.Resources.jquery_1_5_2_min ); // 执行获取按钮并模拟点击的 jQuery 脚本. ie.ExecuteJQuery ( JQuery.Create ( "'[value=Sub]:button'" ).Click ( ) ); }
public FormIEBrowserDoc ( ) { InitializeComponent ( ); // 从当前的 WebBrowser 控件创建 IEBrowser 对象. this.ie = new IEBrowser ( this.webBrowser ); }
private void cmdNavigate_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 将 WebBrowser 导航到 http://www.google.com.hk/. ie.Navigate("http://www.google.com.hk/"); }
private void Form_Main_Load(object sender, EventArgs e) { IEBrowser ie = new IEBrowser(webBrowser_Main); ie.Navigate("https://login.taobao.com/member/login.jhtml?f=top&redirectURL=http%3A%2F%2Ftry.taobao.com%2F"); ie = new IEBrowser(webBrowser_Main); ie.IsNewWindowEnabled = false; }
private void cmdNavigate_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 将 WebBrowser 导航到 http://www.google.com.hk/. ie.Navigate ( "http://www.google.com.hk/" ); }
private void cmd163Blog_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 此处修改为您的 163 博客地址. ie.Navigate("http://<163 博客地址>"); ie.IEFlow.Wait(3); // 安装 jquery 脚本. ie.InstallJQuery(Properties.Resources.jquery_1_5_2_min); // 弹出登录框. ie.ExecuteJQuery(JQuery.Create("'a:contains(登录)'").Attr("'id'", "'denglu'")); ie.ExecuteScript("document.getElementById('denglu').click();"); // 填写用户信息并登录. ie.ExecuteJQuery(JQuery.Create("'.ztxt:text'").Val("'<用户名>'")); ie.ExecuteJQuery(JQuery.Create("'.ztxt:password'").Val("'<密码>'")); ie.ExecuteJQuery(JQuery.Create("'.wbtnok:button'").Attr("'id'", "'dl'")); ie.ExecuteScript("document.getElementById('dl').click();"); ie.IEFlow.Wait(5); // 安装 jquery 脚本. ie.InstallJQuery(Properties.Resources.jquery_1_5_2_min); // 跳转到日志页面. ie.ExecuteJQuery(JQuery.Create("'a:contains(日志)' ").Attr("'id'", "'rz'")); ie.ExecuteScript("document.getElementById('rz').click();"); ie.IEFlow.Wait(5); // 安装 jquery 脚本. ie.InstallJQuery(Properties.Resources.jquery_1_5_2_min); // 跳转到编辑日志页面. ie.ExecuteJQuery(JQuery.Create("'a:contains(写日志)' ").Attr("'id'", "'xrz'")); ie.ExecuteScript("document.getElementById('xrz').click();"); ie.IEFlow.Wait(5); // 安装 jquery 脚本. ie.InstallJQuery(Properties.Resources.jquery_1_5_2_min); // 填写日志内容. ie.ExecuteJQuery(JQuery.Create("'.ztag:text'").Val("'<标题>'")); ie.ExecuteJQuery(JQuery.Create("'#ne-auto-id-source'").Trigger("'click'")); ie.ExecuteJQuery(JQuery.Create("'textarea.ztag'").Val(string.Format("'{0}'", IEBrowser.EscapeCharacter("<日志 html 代码>")))); ie.ExecuteJQuery(JQuery.Create("'#ne-auto-id-source'").Trigger("'click'")); ie.ExecuteScript("document.getElementById('key-093402170-autotag').click();"); ie.IEFlow.Wait(5); // 发布日志. ie.ExecuteJQuery(JQuery.Create("'.fc09:button'").Attr("'id'", "'fb'")); ie.ExecuteScript("document.getElementById('fb').click();"); }
public FormIEBrowser3( ) { InitializeComponent( ); this.ie = new IEBrowser(this.webBrowser, new WebPageState[] { this.state1, this.state2, this.state3 } ); }
//工作流程 private void SignAll() { //IEBrowser IEBrowser ie = new IEBrowser(wb); //JQUERY统计链接数 ie.InstallJQuery(JQuery.CodeMin); ie.ExecuteJQuery(JQuery.Create("'a'"), "__jBs"); int fav_count = ie.ExecuteJQuery <int>(JQuery.Create("__jBs").Length()); //将我喜欢的吧放到List List <string> fav_bar = new List <string>(); for (int index = 0; index < fav_count; index++) { ie.ExecuteJQuery(JQuery.Create("__jBs").Eq(index.ToString()), "__jB"); string fav_text = ie.ExecuteJQuery <string>(JQuery.Create("__jB").Text()); if (fav_text != "发言记录" && fav_text != "贴吧" && fav_text != "百度") { string fav_url = "http://wapp.baidu.com/m?kw=" + UrlEncode(fav_text); fav_bar.Add(fav_url); } } //历遍每个吧,查找签到的链接URL,打开。 int num = 0; foreach (string bar_url in fav_bar) { num++; tips.Text = "签到进度:" + num + "/" + fav_bar.Count; ie.Navigate(bar_url); ie.IEFlow.Wait(new UrlCondition("wait", bar_url, StringCompareMode.StartWith), 10); ie.InstallJQuery(JQuery.CodeMin); ie.ExecuteJQuery(JQuery.Create("'a'"), "__jCs"); int sign_count = ie.ExecuteJQuery <int>(JQuery.Create("__jCs").Length()); for (int index = 0; index < sign_count; index++) { ie.ExecuteJQuery(JQuery.Create("__jCs").Eq(index.ToString()), "__jC"); string sign_text = ie.ExecuteJQuery <string>(JQuery.Create("__jC").Text()); string sign_url = "http://wapp.baidu.com" + ie.ExecuteJQuery <string>(JQuery.Create("__jC").Attr("'href'")); if (sign_text == "签到") { ie.Navigate(sign_url); ie.IEFlow.Wait(new UrlCondition("wait", sign_url, StringCompareMode.StartWith)); } } } if (num != 0) { Environment.Exit(0); } }
public FormIEBrowser3 ( ) { InitializeComponent ( ); this.ie = new IEBrowser ( this.webBrowser, new WebPageState[] { this.state1, this.state2, this.state3 } ); }
private void cmdExecuteJavscript_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser(this.webBrowser); // 在当前页面上执行 javascript 脚本, 弹出对话框. ie.ExecuteScript("alert('你好, IEBrowser!');"); // 可以执行多条 javascript 脚本, 对于脚本中的字符串可以使用 " 或者 '. ie.ExecuteScript("var message = \"我\" + '又来了';alert(message);"); }
private void cmdExecuteJavscript_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser ( this.webBrowser ); // 在当前页面上执行 javascript 脚本, 弹出对话框. ie.ExecuteScript ( "alert('你好, IEBrowser!');" ); // 可以执行多条 javascript 脚本, 对于脚本中的字符串可以使用 " 或者 '. ie.ExecuteScript ( "var message = \"我\" + '又来了';alert(message);" ); }
private void cmdWait_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 导航到页面 http://www.google.com.hk/. ie.Navigate ( "http://www.google.com.hk/" ); // 等待页面载入完毕. ie.IEFlow.Wait ( new UrlCondition ( "wait", "http://www.google.com.hk", StringCompareMode.StartWith ) ); MessageBox.Show ( "页面已经载入" ); }
private void cmdWait_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 导航到页面 http://www.google.com.hk/. ie.Navigate("http://www.google.com.hk/"); // 等待页面载入完毕. ie.IEFlow.Wait(new UrlCondition("wait", "http://www.google.com.hk", StringCompareMode.StartWith)); MessageBox.Show("页面已经载入"); }
private void Form1_Load(object sender, EventArgs e) { Text = ConfigurationManager.AppSettings["name"] + " " + Version; ie = new IEBrowser(this.webBrowser1); ie.IsNewWindowEnabled = false; ie.Scripting = new ScriptForWeb(); this.webBrowser1.Navigate(Application.StartupPath + @"/Main.html"); // this.webBrowser1.DocumentText = "Main.html"; // GetMainHtml(); // 1. 从配置文件中获取相关连接授权信息 // 服务器地址 string broker = ConfigurationManager.AppSettings["broker"]; // 如果服务器地址是锐米发货云,appId 为 应用集成 中的 MQTT 用户名 // 如果为私有云或本地部署,appId 为 Applications 中 Device 节点所挂载的应用的 ID string appId = ConfigurationManager.AppSettings["appId"]; // 如果并未开启 mosquitto 的授权机制,则保持为空 string appSecretKey = ConfigurationManager.AppSettings["appSecretKey"]; // 2. 实例化客户端 client = new Client(broker, appId, appSecretKey); // 3. 相关通知响应 // 3.1 上行消息到达处理交给 DataReceived 方法 client.OnMessage(DataReceived); // 3.2 连接成功时 client.OnConnected(() => { Invoke(new MethodInvoker(delegate { lblState.ForeColor = Color.Green; lblState.Text = "连接成功"; })); }); // 3.3 连接失败、连接断开、异常断开时 client.OnError((c, message) => { Invoke(new MethodInvoker(delegate { lblState.ForeColor = Color.Red; lblState.Text = message; })); }); // 4. 启动客户端 client.Start(); lblState.Text = "连接中..."; }
public override Image ProcessImage(Image image) { IEBrowser.UrlRatioMode ratio; if (!Enum.TryParse(Ratio, true, out ratio)) { ratio = IEBrowser.UrlRatioMode.Screen; } AutoResetEvent resultEvent = new AutoResetEvent(false); IEBrowser browser = new IEBrowser(Url, ratio, resultEvent); WaitHandle.WaitAll(new[] { resultEvent }); return(browser.Thumb); }
private void cmdCopyImage_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 导航到页面 http://www.google.com.hk/imghp. ie.Navigate("http://www.google.com.hk/imghp"); // 等待 5 秒钟, 以便页面载入完毕. ie.IEFlow.Wait(5); // 获取 id 为 hplogo 的 img 的图片. this.pictureBox.Image = ie.CopyImage("'hplogo'"); }
private void cmdInvokeJavascript_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser ( this.webBrowser ); // 安装定义函数 setName 和 getName 的函数到 WebBrowser. ie.InstallScript ( "var name;function setName(name){this.name = name;}function getName(){return this.name;}" ); // 调用 setName 函数, 参数为 "jack". ie.InvokeScript ( "setName", new object[] { "jack" } ); // 调用 getName 函数, 得到结果并弹出对话框. MessageBox.Show ( ie.InvokeScript ( "getName" ).ToString ( ) ); }
private void cmdInvokeJavascript_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser(this.webBrowser); // 安装定义函数 setName 和 getName 的函数到 WebBrowser. ie.InstallScript("var name;function setName(name){this.name = name;}function getName(){return this.name;}"); // 调用 setName 函数, 参数为 "jack". ie.InvokeScript("setName", new object[] { "jack" }); // 调用 getName 函数, 得到结果并弹出对话框. MessageBox.Show(ie.InvokeScript("getName").ToString( )); }
private void btn_OpenLink_Click(object sender, System.EventArgs e) { IEBrowser ie = new IEBrowser(this.webBrowser_Main); string strURL = textBox_Url.Text.Trim().ToString(); if (strURL != "") { ie.Navigate(strURL); } else { MessageBox.Show("没有要打开的链接"); } }
public ScriptCallback(IEBrowser owner) { this.owner = owner; // read JScript.js only once if (scriptPattern != null) { return; } StreamReader rd = File.OpenText(System.AppDomain.CurrentDomain.BaseDirectory + "JScript.js"); scriptPattern = rd.ReadToEnd(); rd.Close(); }
public FormIEBrowser2( ) { InitializeComponent( ); this.ie = new IEBrowser(this.webBrowser, new WebPageState[] { this.loadGoogleState, this.homePageInstallJQueryState, this.testJQueryState, this.searchState, this.resultPageInstallJQueryState, this.nextPageState } ); this.ie.IEFlow.ConditionCompleted += new ConditionCompletedEventHandler <WebPageCondition> (this.ieConditionCompleted); this.ie.IEFlow.RemainWaitTimeChanged += new RemainWaitTimeChangedEventHandler(this.ieRemainWaitTimeChanged); this.ie.IEFlow.StateCompleted += new StateChangedEventHandler <WebPageAction, WebPageCondition> (this.ieStateCompleted); }
//利用委托进行 private void Work() { //IEBrowser IEBrowser ie = new IEBrowser(wb); try { SignAllDelegate sa = new SignAllDelegate(SignAll); this.Invoke(sa); } catch (TimeoutException) { MessageBox.Show("网页打开超时,请检查网络环境,并重试。"); } }
public FormIEBrowser2 ( ) { InitializeComponent ( ); this.ie = new IEBrowser ( this.webBrowser, new WebPageState[] { this.loadGoogleState, this.homePageInstallJQueryState, this.testJQueryState, this.searchState, this.resultPageInstallJQueryState, this.nextPageState } ); this.ie.IEFlow.ConditionCompleted += new ConditionCompletedEventHandler<WebPageCondition> ( this.ieConditionCompleted ); this.ie.IEFlow.RemainWaitTimeChanged += new RemainWaitTimeChangedEventHandler ( this.ieRemainWaitTimeChanged ); this.ie.IEFlow.StateCompleted += new StateChangedEventHandler<WebPageAction, WebPageCondition> ( this.ieStateCompleted ); }
private void cmdDataExchange_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser(this.webBrowser); // 安装跟踪脚本到 WebBrowser, 从而使 __Get 和 __Set 方法可以使用. ie.InstallTrace( ); int age = 10; // 设置姓名和年龄到 WebBrowser, 对于脚本中的字符串可以使用 " 或者 '. ie.__Set("name", "'tom'"); ie.__Set("age", (age + 1).ToString( )); // 获取 WebBrowser 中的 name 和 age, 并弹出对话框. MessageBox.Show(string.Format("name={0}, age={1}", ie.__Get <string> ("name"), ie.__Get <int> ("age"))); }
protected internal IE(object iwebBrowser2, bool finishInitialization) { CheckThreadApartmentStateIsSTA(); var internetExplorer = iwebBrowser2 as IWebBrowser2; if (internetExplorer == null) { throw new ArgumentException("iwebBrowser2 needs to implement shdocvw.IWebBrowser2"); } _ieBrowser = CreateIEBrowser(internetExplorer); if (finishInitialization) { FinishInitialization(null); } }
private void cmdManaged_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser, scripting: new ManagedForScript ( ) ); // 安装跟踪脚本, 执行 jquery 和调用托管代码必需. ie.InstallTrace ( ); // 安装本地的 jquery 脚本. ie.InstallScript ( Properties.Resources.jquery_1_5_2_min ); // 得到搜索框的内容. string key = ie.ExecuteJQuery<string> ( JQuery.Create ( "'[name=q]:text'" ).Val ( ) ); // 通过 javascript 调用托管的对象 ManagedForScript 的 MakeCondition, 生成新的搜索内容, 其实可以直接调用 MakeCondition, 这里只是演示如何调用托管代码. key = ie.ExecuteManaged<string> ( "MakeCondition", parameters: new string[] { "'" + key + "'" } ); // 将新的搜索内容填写入搜索框. ie.ExecuteJQuery ( JQuery.Create ( "'[name=q]:text'" ).Val ( "'" + key + "'" ) ); }
private void cmdNoConflict_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 导航到页面 http://nt.discuz.net/, 此页面中已经定义了 $, 将和 jquery 的 $ 冲突. ie.Navigate("http://nt.discuz.net/"); // 等待 5 秒钟, 以便页面载入完毕. ie.IEFlow.Wait(5); // 安装资源中的 jquery 脚本. ie.InstallJQuery(Properties.Resources.jquery_1_5_2_min); // 解除 jquery 的 $ 定义, 但仍然可以只用 jQuery 定义. ie.ExecuteJQuery(JQuery.Create(false, true).NoConflict( )); // 执行 jquery 脚本 jQuery('*').length, 获得页面上总元素个数. Console.WriteLine("页面上共有 {0} 个元素", ie.ExecuteJQuery(JQuery.Create("'*'", false).Length( ))); }
private void cmdManaged_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser, scripting: new ManagedForScript( )); // 安装跟踪脚本, 执行 jquery 和调用托管代码必需. ie.InstallTrace( ); // 安装本地的 jquery 脚本. ie.InstallScript(Properties.Resources.jquery_1_5_2_min); // 得到搜索框的内容. string key = ie.ExecuteJQuery <string> (JQuery.Create("'[name=q]:text'").Val( )); // 通过 javascript 调用托管的对象 ManagedForScript 的 MakeCondition, 生成新的搜索内容, 其实可以直接调用 MakeCondition, 这里只是演示如何调用托管代码. key = ie.ExecuteManaged <string> ("MakeCondition", parameters: new string[] { "'" + key + "'" }); // 将新的搜索内容填写入搜索框. ie.ExecuteJQuery(JQuery.Create("'[name=q]:text'").Val("'" + key + "'")); }
public static void SetBrowserFeatureControl(IEBrowser browser = IEBrowser.Installed) { // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx // FeatureControl settings are per-process var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName); // make the control is not running inside Visual Studio Designer if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0) { return; } var browserEmulationMode = browser == IEBrowser.Installed ? GetBrowserEmulationMode() : (UInt32)browser; SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, browserEmulationMode); SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1); SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1); SetBrowserFeatureControlKey("FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1); SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1); SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1); SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI ", fileName, 0); SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1); SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0); SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0); SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0); SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1); SetBrowserFeatureControlKey("FEATURE_SCRIPTURL_MITIGATION", fileName, 1); SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0); SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1); SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1); SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1); SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1); SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0); SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1); SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0); SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1); SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0); SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1); }
//判断网页是否打开 private void OpenIndexPage() { //IEBrowser IEBrowser ie = new IEBrowser(wb); try { ie.Navigate(baidu_wapp_favbar); ie.IEFlow.Wait(new UrlCondition("wait", baidu_wapp_favbar, StringCompareMode.StartWith), 10); GetInnerHtmlDelegate gih = new GetInnerHtmlDelegate(GetInnerHtml); string innerhtml = this.Invoke(gih).ToString(); Work(); } catch (NullReferenceException) { OpenIndexPage(); } catch (TimeoutException) { MessageBox.Show("网页打开超时,请检查网络环境,并重试。"); } }
private void cmdExecuteJQuery_Click(object sender, EventArgs e) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser(this.webBrowser); // 导航到页面 http://www.google.com.hk/. ie.Navigate("http://www.google.com.hk/"); // 等待页面载入完毕. ie.IEFlow.Wait(new UrlCondition("wait", "http://www.google.com.hk", StringCompareMode.StartWith)); // 安装本地的 jquery 脚本. ie.InstallJQuery(JQuery.CodeMin); // 执行 jquery 脚本 $('*').length, 获得页面上总元素个数. Console.WriteLine("页面上共有 {0} 个元素", ie.ExecuteJQuery(JQuery.Create("'*'").Length( ))); // 执行 jquery 脚本 $('a'), 获得页面上所有的 a 元素并将结果保存在 __jAs 变量中. ie.ExecuteJQuery(JQuery.Create("'a'"), "__jAs"); // 得到 __jAs 变量中包含的 a 元素的个数. int count = ie.ExecuteJQuery <int> (JQuery.Create("__jAs").Length( )); for (int index = 0; index < count; index++) { // 得到 __jAs 变量中索引为 index 的 a 元素, 并保存在 __jA 变量中. ie.ExecuteJQuery(JQuery.Create("__jAs").Eq(index.ToString( )), "__jA"); // 输出 a 元素的 innerText 和 href 属性. Console.WriteLine(string.Format( "a[{0}], '{1}', '{2}'", index, ie.ExecuteJQuery <string> (JQuery.Create("__jA").Text( )), ie.ExecuteJQuery <string> (JQuery.Create("__jA").Attr("'href'")) ) ); } }
private void cmdAdd_Click ( object sender, EventArgs e ) { // 创建 IEBrowser 对象, 用来控制窗口的 WebBrowser 控件. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 载入已经放在运行目录的页面 ButtonClick.htm. ie.Navigate ( Path.Combine ( AppDomain.CurrentDomain.BaseDirectory + "ButtonClick.htm" ) ); // 等待 ButtonClick.htm 完全载入. ie.IEFlow.Wait ( new UrlCondition ( "wait", "ButtonClick.htm", StringCompareMode.EndWith ) ); // 模拟具有惟一 id 属性的按钮点击. // 方法1: 执行 javascript 脚本来获取按钮并调用其 click 方法. ie.ExecuteScript ( "document.getElementById('cmdAdd').click();" ); // 方法2: 安装跟踪和 jQuery 脚本后, 执行 jQuery 来模拟点击按钮. // 安装跟踪脚本. ie.InstallTrace ( ); // 安装在资源中的 jQuery 脚本. ie.InstallScript ( Properties.Resources.jquery_1_5_2_min ); // 执行获取按钮并模拟点击的 jQuery 脚本. ie.ExecuteJQuery ( JQuery.Create ( "'#cmdAdd'" ).Click ( ) ); }
//http://www.sufeinet.com/forum.php?mod=viewthread&tid=6976&extra=page%3D1&page=1& private void btnlogin_Click(object sender, EventArgs e) { string loginUrl = "http://219.142.64.12/login.aspx"; IEBrowser ie = new IEBrowser(webBrowser1); ie.Navigate(loginUrl); ie.IEFlow.Wait(new UrlCondition("wait", loginUrl, zoyobar.shared.panzer.StringCompareMode.StartWith)); MainCookie Cc = new MainCookie(); string str = MainCookie.GetCookies(loginUrl); //获取得到的cookie string[] strs = str.Split(';'); //将cookie字符串处理成Cookie对象 for (int i = 0; i < strs.Length; i++) { try { Cookie ck = new Cookie(); ck.Name = strs[i].Split('=')[0].Trim(); ck.Value = strs[i].Split('=')[1].Trim(); ck.Domain = webBrowser1.Document.Domain; mf.cc.Add(ck); //这里的cc 是CookieContainer,这里我定义到了主窗体中。 如果处理成CookieCollection 也可,方法是一样的.这样自己构造一个cookie集合,. } catch { } } //由于构造静态变量,变量被申明以后是存在共享空间中,直到整个程序结束才被释放,所以拿来传递窗体间的值再合适不过.也不用写繁琐的委托.当然如果你明白该怎样处理委托,那么可以任选一种方法.. MainCookie.Cc = mf.cc; MainCookie.Cookie = str; //既然已经得到了cookie,那么就做你想做的事情去吧... // this.Dispose(); // MessageBox.Show(str.ToString());//这个截取后4位可以得到验证码。不用自己手动识别了,呵呵~~~ //截取文本后四位 HtmlElement name = webBrowser1.Document.GetElementById("UserLogin2_txtEmailName"); HtmlElement pwd = webBrowser1.Document.GetElementById("UserLogin2_txtPassword"); HtmlElement CheckCode = webBrowser1.Document.GetElementById("UserLogin2_txtDatabase"); HtmlElement subm = webBrowser1.Document.GetElementById("UserLogin2_ImgCmdLogin"); name.Focus(); name.SetAttribute("value", "*****@*****.**"); pwd.Focus(); pwd.SetAttribute("value", "770716"); CheckCode.Focus(); CheckCode.SetAttribute("value", str.Substring(str.Length - 4)); subm.Focus(); subm.SetAttribute("onclick", "javascript:return true;"); //todo:验证码变了,也要变 ie.InstallTrace(); string js = "function CheckData(){return true;}"; ie.InstallScript(js); webBrowser1.Document.InvokeScript("Passfn"); subm.InvokeMember("click"); // MessageBox.Show(str.ToString()); //此处用图象识别功能吧! //todo:web登录信息保存了xml以后更改 //string code = webBrowser1.Document.Cookie; //if (!string.IsNullOrEmpty(code)) //{ // //填入验证框 // HtmlElement chekcode = webBrowser1.Document.GetElementById("UserLogin2_txtDatabase"); // chekcode.Focus(); // chekcode.SetAttribute("value", code.Substring(66, 4)); // //模拟提交 // HtmlElement subm = webBrowser1.Document.GetElementById("UserLogin2_ImgCmdLogin"); // subm.Focus(); // subm.InvokeMember("click"); //} }
public FormIEBrowser5 ( ) { InitializeComponent ( ); this.ie = new IEBrowser ( this.webBrowser ); }
public ScriptCallback(IEBrowser owner) { this.owner = owner; // read JScript.js only once if (scriptPattern != null) return; StreamReader rd = File.OpenText(System.AppDomain.CurrentDomain.BaseDirectory + "JScript.js"); scriptPattern = rd.ReadToEnd(); rd.Close(); }
private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { skinButtom1.Enabled = true; if (webBrowser1.Url.ToString().Contains("http://concierge.apple.com/geniusbar/R484")) { IEBrowser ie = new IEBrowser(this.webBrowser1); ie.ExecuteScript("if($('#serviceType_iPhone').length){$('#serviceType_iPhone').trigger('click');$('#fwdButtonC').trigger('click');}"); ie.ExecuteScript("if($('a[href=#]').text()=='进行 Genius Bar 天才吧预约')$('a[href=#]').trigger('click');"); } if (webBrowser1.Url.ToString() == ("http://concierge.apple.com/geniusbar/R484/timeslots")) { IEBrowser ie = new IEBrowser(this.webBrowser1); ie.ExecuteScript("if($('.notimesavailable:visible').length)location.href='https://idmsa.apple.com/IDMSWebAuth/login.html?appIdKey=990d5c9e38720f4e832a8009a0fe4cad7dd151f99111dbea0df5e2934f267ec8&language=CN-zh&segment=R484&grpcode=g001¶mcode=h006&path=%2Fgeniusbar%2FR484%2Fsignin%2Fack&path2=%2Fgeniusbar%2FR484%2Fsignin%2Fack';else{$('#timeslotC').click();$('#fwdButtonC').click();}"); } if (webBrowser1.Url.ToString().Contains("https://idmsa.apple.com/IDMSWebAuth/login.html?appIdKey=990d5c9e38720f4e832a8009a0fe4cad7dd151f99111dbea0df5e2934f267ec8&language=CN-zh&segment=R484&grpcode=g001¶mcode=h006&path=/geniusbar/R484/signin/ack&path2=/geniusbar/R484/signin/ack")) { Thread.Sleep(2000); skinButtom1_Click_1(null, null); } if (webBrowser1.Url.ToString().Contains("/retail/")) { webBrowser1.Navigate("https://idmsa.apple.com/IDMSWebAuth/login.html?appIdKey=990d5c9e38720f4e832a8009a0fe4cad7dd151f99111dbea0df5e2934f267ec8&language=CN-zh&segment=R484&grpcode=g001¶mcode=h006&path=%2Fgeniusbar%2FR484%2Fsignin%2Fack&path2=%2Fgeniusbar%2FR484%2Fsignin%2Fack"); } if (webBrowser1.Url.ToString().Contains("reservationConfirmation")) { count++; SetText("恭喜:你已经成功抢到"+count+"张票了!"); webBrowser1.Navigate("https://idmsa.apple.com/IDMSWebAuth/login.html?appIdKey=990d5c9e38720f4e832a8009a0fe4cad7dd151f99111dbea0df5e2934f267ec8&language=CN-zh&segment=R484&grpcode=g001¶mcode=h006&path=%2Fgeniusbar%2FR484%2Fsignin%2Fack&path2=%2Fgeniusbar%2FR484%2Fsignin%2Fack"); } }
//翻页的方法 /// <summary> /// 模式<a href="?pid=3&page=2">下一页</a> /// </summary> /// <param name="srcUrl">html页面的URL</param> /// <returns>下一页的URL</returns> private string AutoClickPageBar(string srcUrl) { //WebBrowser iBrowser = new WebBrowser(); IEBrowser ie = new IEBrowser(new WebBrowser()); ie.Navigate(srcUrl); //思路一:查找根据文本确定文本所在标签 //思路二:在所有<a>标签中查找文本是“下一页”的<a>标签 //思路三:正则表达式 string url = ""; return url; }
private void cmdFlowNWPC_Click ( object sender, EventArgs e ) { // 定义载入 google 的页面状态. WebPageState loadGoogle = new WebPageState ( "load google", // 状态的名称. completedStateSetting: new WebPageNextStateSetting ( "load blog", true ), // 在页面完成时, 自动跳转到载入 blog 的状态. startAction: new NavigateAction ( "http://www.google.com.hk" ), // 页面状态的开始动作为载入 http://www.google.com.hk. condition: new UrlCondition ( // 判断页面状态是否完成的地址条件. "google condition", // 条件名称. "http://www.google.com.hk", // 载入的页面以 http://www.google.com.hk 开始时, 认为此地址条件成立. StringCompareMode.StartWith ) ); // 定义载入 blog 的页面状态. WebPageState loadMyBlog = new WebPageState ( "load blog", // 状态的名称. startAction: new NavigateAction ( "http://blog.sina.com.cn/zoyobar" ), // 页面状态的开始动作为载入 http://blog.sina.com.cn/zoyobar. completedAction: new ExecuteJavaScriptAction ( "alert('我是从 google 页面跳转过来的!');" ), // 当页面状态完成后, 执行一条 javascript 脚本. condition: new UrlCondition ( // 判断页面状态是否完成的地址条件. "blog condition", // 条件名称. "http://blog.sina.com.cn/zoyobar", // 载入的页面以 http://blog.sina.com.cn/zoyobar 开始时, 认为此地址条件成立. StringCompareMode.StartWith ) ); // 从当前的 WebBrowser 控件创建 IEBrowser 对象, 并赋予刚才定义的流程. IEBrowser ie = new IEBrowser ( this.webBrowser, new WebPageState[] { loadGoogle, loadMyBlog } ); // 从载入 google 页面的状态开始. ie.IEFlow.JumpToState ( "load google" ); }
private void cmdDataExchange_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象, WebBrowser 的 Url 属性已经设置为 "about:blank". IEBrowser ie = new IEBrowser ( this.webBrowser ); // 安装跟踪脚本到 WebBrowser, 从而使 __Get 和 __Set 方法可以使用. ie.InstallTrace ( ); int age = 10; // 设置姓名和年龄到 WebBrowser, 对于脚本中的字符串可以使用 " 或者 '. ie.__Set ( "name", "'tom'" ); ie.__Set ( "age", ( age + 1 ).ToString ( ) ); // 获取 WebBrowser 中的 name 和 age, 并弹出对话框. MessageBox.Show ( string.Format ( "name={0}, age={1}", ie.__Get<string> ( "name" ), ie.__Get<int> ( "age" ) ) ); }
public static void Discuz ( IEBrowser ie, string userName, string password, string url, string title, string content ) { // 导航到页面 dz 论坛的页面. ie.Navigate ( url ); // 等待 10 秒钟, 以便页面载入完毕. ie.IEFlow.Wait ( 10 ); // 安装资源中的 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 解除 jquery 的 $ 定义, 但仍然可以只用 jQuery 定义. ie.ExecuteJQuery ( JQuery.Create ( false, true ).NoConflict ( ) ); // 安装 javascript 函数 clickLink, 根据超链接的文本点击超链接. ie.InstallScript ( "function clickLink(text) {" + " links = document.getElementsByTagName('a');" + " for(var index = 0; index < links.length; index++)" + " {" + " if(links[index].innerText == text)" + " {" + " links[index].click();" + " break;" + " }" + " }" + "}" ); // 是否存在已经登录后显示的短消息. if ( ie.ExecuteJQuery<int> ( JQuery.Create ( "'#pm_ntc'", false ).Length ( ) ) == 1 ) { // 调用 javascript 函数 clickLink, 模拟点击退出链接. ie.InvokeScript ( "clickLink", new object[] { "退出" } ); // 等待 3 秒钟, 以便退出完毕. ie.IEFlow.Wait ( 3 ); // 重新调用自身. Discuz ( ie, userName, password, url, title, content ); return; } // 设置用户名. ie.ExecuteJQuery ( JQuery.Create ( "'#ls_username'", false ).Val ( "'"+userName+"'" ) ); // 设置密码. ie.ExecuteJQuery ( JQuery.Create ( "'#ls_password'", false ).Val ( "'"+password+"'" ) ); // 密码框获得焦点. ie.ExecuteJQuery ( JQuery.Create ( "'#ls_password'", false ).Focus ( ) ); // 等待 5 秒钟以显示验证码. ie.IEFlow.Wait ( 5 ); // 获取验证码并显示给用户输入. FormVCode vCodeWindow = new FormVCode ( ); vCodeWindow.Image = ie.CopyImage ( "'vcodeimg1'" ); // 用户是否确认. if ( vCodeWindow.ShowDialog ( ) == DialogResult.OK ) { // 验证码框获得焦点. ie.ExecuteJQuery ( JQuery.Create ( "'#vcodetext_header1'", false ).Focus ( ) ); // 填写验证码并多加 1. ie.ExecuteJQuery ( JQuery.Create ( "'#vcodetext_header1'", false ).Val ( "'" + vCodeWindow.VCode + "1'" ) ); // 模拟一个退格键, 删除掉 1. SendKeys.Send ( "{Backspace}" ); // 等待 2 秒. ie.IEFlow.Wait ( 2 ); // 登录框提交. ie.ExecuteJQuery ( JQuery.Create ( "'#lsform'", false ).Submit() ); // 等待 5 秒, 以便登录完成. ie.IEFlow.Wait ( 5 ); // 是否是验证码错误. if ( ie.ExecuteJQuery<int> ( JQuery.Create ( "'p:contains(验证码错误)'", false ).Length ( ) ) == 1 ) { // 验证码错误重新登录. Discuz ( ie, userName, password, url, title, content ); return; } TOPIC: // 随机导航至某一话题. ie.Navigate ( "http://nt.discuz.net/showtopic-" + new Random ( ).Next ( 11000, 18000 ).ToString() + ".html" ); // 等待 5 秒, 以便页面完成. ie.IEFlow.Wait ( 5 ); // 安装 jquery 脚本的一系列操作. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); ie.ExecuteJQuery ( JQuery.Create ( false, true ).NoConflict ( ) ); // 话题不存在则重新选择. if ( ie.ExecuteJQuery<int> ( JQuery.Create ( "'p:contains(该主题不存在)'", false ).Length ( ) ) == 1 ) goto TOPIC; // 切换源码编辑方式. ie.InvokeScript ( "clickLink", new object[] { "Code" } ); // 填写内容. ie.ExecuteJQuery ( JQuery.Create ( "'#quickpostmessage'", false ).Val ( "'" + content + "'" ) ); // 验证码框获得焦点. ie.ExecuteJQuery ( JQuery.Create ( "'#vcodetext1'", false ).Focus ( ) ); // 等待 5 秒钟以显示验证码. ie.IEFlow.Wait ( 3 ); // 获取验证码并显示给用户输入. vCodeWindow = new FormVCode ( ); vCodeWindow.Image = ie.CopyImage ( "'vcodeimg1'" ); // 用户是否确认. if ( vCodeWindow.DialogResult == DialogResult.OK ) { // 填写验证码并多加1. ie.ExecuteJQuery ( JQuery.Create ( "'#vcodetext1'", false ).Val ( "'" + vCodeWindow.VCode + "1'" ) ); // 模拟一个退格键, 删除掉 1. SendKeys.Send ( "{Backspace}" ); // 等待 2 秒. ie.IEFlow.Wait ( 3 ); // 提交. ie.ExecuteJQuery ( JQuery.Create ( "'#quickpostsubmit'", false ).Click ( ) ); } else { Discuz ( ie, userName, password, url, title, content ); return; } } else { Discuz ( ie, userName, password, url, title, content ); return; } }
private void cmd163Blog_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 此处修改为您的 163 博客地址. ie.Navigate ( "http://<163 博客地址>" ); ie.IEFlow.Wait ( 3 ); // 安装 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 弹出登录框. ie.ExecuteJQuery ( JQuery.Create ( "'a:contains(登录)'" ).Attr ( "'id'", "'denglu'" ) ); ie.ExecuteScript ( "document.getElementById('denglu').click();" ); // 填写用户信息并登录. ie.ExecuteJQuery ( JQuery.Create ( "'.ztxt:text'" ).Val ( "'<用户名>'" ) ); ie.ExecuteJQuery ( JQuery.Create ( "'.ztxt:password'" ).Val ( "'<密码>'" ) ); ie.ExecuteJQuery ( JQuery.Create ( "'.wbtnok:button'" ).Attr ( "'id'", "'dl'" ) ); ie.ExecuteScript ( "document.getElementById('dl').click();" ); ie.IEFlow.Wait ( 5 ); // 安装 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 跳转到日志页面. ie.ExecuteJQuery ( JQuery.Create ( "'a:contains(日志)' " ).Attr ( "'id'", "'rz'" ) ); ie.ExecuteScript ( "document.getElementById('rz').click();" ); ie.IEFlow.Wait ( 5 ); // 安装 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 跳转到编辑日志页面. ie.ExecuteJQuery ( JQuery.Create ( "'a:contains(写日志)' " ).Attr ( "'id'", "'xrz'" ) ); ie.ExecuteScript ( "document.getElementById('xrz').click();" ); ie.IEFlow.Wait ( 5 ); // 安装 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 填写日志内容. ie.ExecuteJQuery ( JQuery.Create ( "'.ztag:text'" ).Val ( "'<标题>'" ) ); ie.ExecuteJQuery ( JQuery.Create ( "'#ne-auto-id-source'" ).Trigger ( "'click'" ) ); ie.ExecuteJQuery ( JQuery.Create ( "'textarea.ztag'" ).Val ( string.Format ( "'{0}'", IEBrowser.EscapeCharacter ( "<日志 html 代码>" ) ) ) ); ie.ExecuteJQuery ( JQuery.Create ( "'#ne-auto-id-source'" ).Trigger ( "'click'" ) ); ie.ExecuteScript ( "document.getElementById('key-093402170-autotag').click();" ); ie.IEFlow.Wait ( 5 ); // 发布日志. ie.ExecuteJQuery ( JQuery.Create ( "'.fc09:button'" ).Attr ( "'id'", "'fb'" ) ); ie.ExecuteScript ( "document.getElementById('fb').click();" ); }
private void cmdCopyImage_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 导航到页面 http://www.google.com.hk/imghp. ie.Navigate ( "http://www.google.com.hk/imghp" ); // 等待 5 秒钟, 以便页面载入完毕. ie.IEFlow.Wait ( 5 ); // 获取 id 为 hplogo 的 img 的图片. this.pictureBox.Image = ie.CopyImage ( "'hplogo'" ); }
//工作流程 private void SignAll() { //IEBrowser IEBrowser ie = new IEBrowser(wb); //JQUERY统计链接数 ie.InstallJQuery(JQuery.CodeMin); ie.ExecuteJQuery(JQuery.Create("'a'"), "__jBs"); int fav_count = ie.ExecuteJQuery<int>(JQuery.Create("__jBs").Length()); //将我喜欢的吧放到List List<string> fav_bar = new List<string>(); for (int index = 0; index < fav_count; index++) { ie.ExecuteJQuery(JQuery.Create("__jBs").Eq(index.ToString()), "__jB"); string fav_text = ie.ExecuteJQuery<string>(JQuery.Create("__jB").Text()); if (fav_text != "发言记录" && fav_text != "贴吧" && fav_text != "百度") { string fav_url = "http://wapp.baidu.com/m?kw=" + UrlEncode(fav_text); fav_bar.Add(fav_url); } } //历遍每个吧,查找签到的链接URL,打开。 int num = 0; foreach (string bar_url in fav_bar) { num++; tips.Text = "签到进度:" + num + "/" + fav_bar.Count; ie.Navigate(bar_url); ie.IEFlow.Wait(new UrlCondition("wait", bar_url, StringCompareMode.StartWith), 10); ie.InstallJQuery(JQuery.CodeMin); ie.ExecuteJQuery(JQuery.Create("'a'"), "__jCs"); int sign_count = ie.ExecuteJQuery<int>(JQuery.Create("__jCs").Length()); for (int index = 0; index < sign_count; index++) { ie.ExecuteJQuery(JQuery.Create("__jCs").Eq(index.ToString()), "__jC"); string sign_text = ie.ExecuteJQuery<string>(JQuery.Create("__jC").Text()); string sign_url = "http://wapp.baidu.com" + ie.ExecuteJQuery<string>(JQuery.Create("__jC").Attr("'href'")); if (sign_text == "签到") { ie.Navigate(sign_url); ie.IEFlow.Wait(new UrlCondition("wait", sign_url, StringCompareMode.StartWith)); } } } if (num != 0) { Environment.Exit(0); } }
private void willWebSend() { IEBrowser ie = new IEBrowser(this.webBrowser1); // ie.InstallTrace(); ie.Navigate("http://219.142.64.12/Admin/oamis/inforReport.apsx"); webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(mywebBrowser_DocumentCompleted); ie.IEFlow.Wait(new UrlCondition("wait", "http://219.142.64.12/Admin/oamis/inforReport.apsx", zoyobar.shared.panzer.StringCompareMode.StartWith)); }
private void mywebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.ReadyState == WebBrowserReadyState.Complete) { for (int i = 0; i < listWeb.Count; i++) { #region 用IEBrowser方法执行JS IEBrowser ie = new IEBrowser(this.webBrowser1); ie.InstallTrace(); string js = "function myfn(tit,sou,con){" + "document.getElementById('InforReport1_txtTitle').value=tit;" + "document.getElementById('InforReport1_txtInfoFrom').value=sou;" + "editor.html(con);" + "" + "}"; ie.InstallScript(js); webBrowser1.Document.InvokeScript("myfn", new string[] { listWeb[i].Title, listWeb[i].Site, listWeb[i].Content }); HtmlElement WebSumbit = webBrowser1.Document.All["InforReport1_btn"]; WebSumbit.InvokeMember("Click"); //更改lab显示 labwebNum(i + 1); Thread.Sleep(2000); //标记已上报 mf.DS.upsend.FindByTitle(listWeb[i].Title).WebSend = "已报送"; //重新加载listview mf.WaitSendFmReload(); #endregion } } }
private void cmdNoConflict_Click ( object sender, EventArgs e ) { // 从当前的 WebBrowser 控件创建 IEBrowser 对象. IEBrowser ie = new IEBrowser ( this.webBrowser ); // 导航到页面 http://nt.discuz.net/, 此页面中已经定义了 $, 将和 jquery 的 $ 冲突. ie.Navigate ( "http://nt.discuz.net/" ); // 等待 5 秒钟, 以便页面载入完毕. ie.IEFlow.Wait ( 5 ); // 安装资源中的 jquery 脚本. ie.InstallJQuery ( Properties.Resources.jquery_1_5_2_min ); // 解除 jquery 的 $ 定义, 但仍然可以只用 jQuery 定义. ie.ExecuteJQuery ( JQuery.Create ( false, true ).NoConflict ( ) ); // 执行 jquery 脚本 jQuery('*').length, 获得页面上总元素个数. Console.WriteLine ( "页面上共有 {0} 个元素", ie.ExecuteJQuery ( JQuery.Create ( "'*'", false ).Length ( ) ) ); }
/// <summary> /// Initializes a new instance of the <see cref="BrowserUtility"/> class. /// </summary> public BrowserUtility() { this.browser = new IEBrowser(); }