private SHDocVw.WebBrowser CreateNewWebBrowser() { this.toolSource.Enabled = true; System.Windows.Forms.WebBrowser TmpWebBrowser = new System.Windows.Forms.WebBrowser(); if (this.WebBrowserTab.TabPages.Count == 1 && this.WebBrowserTab.TabPages[0].Controls.Count == 0) { this.WebBrowserTab.TabPages[0].Controls.Add(TmpWebBrowser); } else { this.WebBrowserTab.TabPages[0].Controls.Clear(); this.WebBrowserTab.TabPages[0].Controls.Add(TmpWebBrowser); } TmpWebBrowser.Dock = DockStyle.Fill; SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)TmpWebBrowser.ActiveXInstance; wb.CommandStateChange += new SHDocVw.DWebBrowserEvents2_CommandStateChangeEventHandler(this.wb_CommandStateChange); wb.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.wb_BeforeNavigate2); wb.ProgressChange += new SHDocVw.DWebBrowserEvents2_ProgressChangeEventHandler(this.wb_ProgressChange); wb.StatusTextChange += new SHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.wb_StatusTextChange); wb.NavigateError += new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(this.wb_NavigateError); wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.wb_NavigateComplete2); wb.TitleChange += new SHDocVw.DWebBrowserEvents2_TitleChangeEventHandler(this.wb_TitleChange); wb.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.wb_DocumentComplete); wb.NewWindow2 += new SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(this.wb_NewWindow2); return(wb); }
private void GoUrl() { string url = this.txtUrl.Text; SHDocVw.WebBrowser wb = CreateNewWebBrowser(); // Return if nowhere to go if (url == "") { return; } try { Cursor.Current = Cursors.WaitCursor; Object o = null; wb.Navigate(url, ref o, ref o, ref o, ref o); } finally { int i = this.txtUrl.Items.IndexOf(url); if (i == -1) { this.txtUrl.Items.Add(url); } Cursor.Current = Cursors.Default; } }
private void Form1_Load(object sender, EventArgs e) { SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance; wb.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler( (object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel) => { if (PostData == null) { this.listBox.Items.Add("[GET] " + URL); this.listBox.Items.Add(""); } else { string PostDATAStr = System.Text.Encoding.ASCII.GetString((Byte[])PostData); this.listBox.Items.Add("[POST] " + URL); this.listBox.Items.Add("[POST DATA] " + PostDATAStr); this.listBox.Items.Add(""); } }); }
void SetupBrowser(object sender, WebBrowserDocumentCompletedEventArgs e) { DocumentCompleted -= SetupBrowser; SHDocVw.WebBrowser xBrowser = (SHDocVw.WebBrowser)ActiveXInstance; xBrowser.BeforeNavigate2 += BeforeNavigate; DocumentCompleted += PageLoaded; }
//ie 프로세스 생성 private void makeIeProcess(string url) { /* * have to check resolution * basic resolution : 800 x 600 * */ url = checkUrl(macroString.Substring(macroString.IndexOf("=") + 1)); Console.WriteLine(url); if (ie == null) { ie = new InternetExplorer(); webBrowser = (SHDocVw.WebBrowser)ie; webBrowser.Visible = true; ie.Left = 0; ie.Top = 0; ie.Height = int.Parse(browserXSizeTextbox.Text); ie.Width = int.Parse(browserYSizeTextbox.Text); } //User-Agent: Mozilla / 5.0(Linux; U; Android 2.2) AppleWebKit / 533.1(KHTML, like Gecko) Version / 4.0 Mobile Safari/ 533.1" // "User-Agent: Mozilla/7.0(Linux; Android 7.0.0; SGH-i907) AppleWebKit/664.76 (KHTML, like Gecko) Chrome/87.0.3131.15 Mobile Safari/664.76 (Windows NT 10.0; WOW64; Trident/7.0; Touch; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; rv:11.0) like Gecko" log.Debug("navigate2 start"); ie.Navigate2(url, null, null, null, null); log.Debug("navigate2 complete"); ie.Wait(); prevUrl = url; log.Debug("wait complete"); }
/// <summary> /// Navigates the login page. /// </summary> private void LoginForm_Load(object sender, EventArgs e) { loginBrowser.Navigate("http://auth.mercadolibre.com/authorization?platform_id=mp&response_type=token&client_id=12214"); loginBrowser.NewWindow += new CancelEventHandler(loginBrowser_NewWindow); SHDocVw.WebBrowser axBrowser = (SHDocVw.WebBrowser) this.loginBrowser.ActiveXInstance; axBrowser.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axBrowser_NewWindow3); }
private void Form1_Load(object sender, EventArgs e) { SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance; wb.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(WebBrowser_BeforeNavigate2); webBrowser1.Url = new Uri("http://192.168.4.15"); textBoxURL.Text = "http://192.168.4.15"; }
protected override void OnExplorerAttached(EventArgs ea) { SHDocVw.WebBrowser IEDocument = this.GetIEDocument(); IEDocument.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(BeforeNavigate); IEDocument.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(AfterNavigate); IEDocument.FileDownload += new DWebBrowserEvents2_FileDownloadEventHandler(IEDocument_FileDownload); base.OnExplorerAttached(ea); }
public void AfterNavigate(object iDisp, ref object URL) { SHDocVw.WebBrowser IEDocument = GetIEDocument(); MakeVisible(); //mshtml.HTMLDocument HTML = (mshtml.HTMLDocument) IEDocument.Document; //HTML.cookie //HTML.attachEvent(iDisp) btnDownload.Enabled = videoSites.IsVideoSite(IEDocument.LocationURL); }
private HTMLDocument GetDocument() { try { SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance; HTMLDocument htm = (HTMLDocument)wb.Document; return(htm); } catch (System.Exception ex) { throw (ex); } }
private void btnDownload_Click(object sender, System.EventArgs e) { try { SHDocVw.WebBrowser IEDocument = GetIEDocument(); DownloadURL(IEDocument.LocationURL); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void VisualizeCallback(object sender, EventArgs e) { //here we need to open the xml file //we can either open it using a system command (open a webpage) //or we can open it in visual studio //2. figure out how to open via normal web browser // easy, just call start process try { if (CodeCommandsUnavailable()) { throw new Exception(); } string filename = ""; if (IsGeneratedFileAvailable(".xml", ref filename)) { string url = "file://" + filename; //before navigating, apparently you have to do this. CoInternetSetFeatureEnabled(INTERNETFEATURELIST.FEATURE_LOCALMACHINE_LOCKDOWN, SET_FEATURE_ON_PROCESS, false); Window window = App().ItemOperations.Navigate(url, vsNavigateOptions.vsNavigateOptionsDefault); window.Caption = "opC++ Visualization"; SHDocVw.WebBrowser browser = window.Object as SHDocVw.WebBrowser; if (browser != null) { mshtml.HTMLDocument doc = browser.Document as mshtml.HTMLDocument; mshtml.HTMLDocumentEvents2_Event ievent = doc as mshtml.HTMLDocumentEvents2_Event; //NOTE: theres some issue with this // it seems to work the first time but doesn't after that // I suspect this could be a garbage collection issue. if (ievent != null) { ievent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler(ClickVisualize); } } return; } } catch (Exception) { } //Now we can add our event handler //m_hostedBrowser.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(NavigateComplete2); }
public int SetSite([MarshalAs(UnmanagedType.IUnknown)] object site) { if (site != null) { webBrowser = (SHDocVw.WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(OnDocumentComplete); } else { webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(OnDocumentComplete); webBrowser = null; } return(0); }
public FormBrowser(FormMain fm) { this.InitializeComponent(); this.mainfrm = fm; this.LoadDefaultPage(); try { this.wb = (SHDocVw.WebBrowser) this.WCRBrowser.ActiveXInstance; this.wb.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(wb_BeforeNavigate2); this.wb.NewWindow3 += new DWebBrowserEvents2_NewWindow3EventHandler(wb_NewWindow3); } catch { } }
public int SetSite(object site) { if (site != null) { webBrowser = (SHDocVw.WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); } else { webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); webBrowser = null; } return(0); }
public void AfterNavigate(object iDisp, ref object URL) { SHDocVw.WebBrowser IEDocument = GetIEDocument(); MakeVisible(); mshtml.HTMLDocument HTML = (mshtml.HTMLDocument)IEDocument.Document; // save cookies //StreamWriter sw=new StreamWriter(Settings.MyDownloaderPath + "_cookie"); //sw.Write(HTML.cookie); //sw.Close(); //HTML.cookie //HTML.attachEvent(iDisp) btnDownload.Enabled = videoSites.IsVideoSite(IEDocument.LocationURL); }
private void wb_DocumentComplete(object pDisp, ref object URL) { SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance; if (wb.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { this.txtUrl.Text = wb.LocationURL; this.toolStripProgressBar1.Value = 0; this.toolStripProgressBar1.Visible = false; } this.textBox1.Text = ((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).Document.Cookie.ToString(); }
private void FrmBrowser_Load(object sender, EventArgs e) { try { Share.SuppressWininetBehavior(); webBrowser1.Navigate("https://rd.tencent.com/outsourcing/attendances/add"); wb = webBrowser1.ActiveXInstance as SHDocVw.WebBrowser; wb.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); //waitwebCompleted(); //SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser; //wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public FormBrowser(FormMain fm) { this.InitializeComponent(); this.mainfrm = fm; this.LoadDefaultPage(); this.toolStripResendResponse.Visible = true; try { this.wb = (SHDocVw.WebBrowser) this.WCRBrowser.ActiveXInstance; //this.wb.add_BeforeNavigate2(new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.wb_BeforeNavigate2)); this.wb.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.wb_BeforeNavigate2); //this.wb.add_NewWindow3(new DWebBrowserEvents2_NewWindow3EventHandler(this.wb_NewWindow3)); this.wb.NewWindow3 += new DWebBrowserEvents2_NewWindow3EventHandler(this.wb_NewWindow3); } catch { } }
private void wb_ProgressChange(int Progress, int ProgressMax) { this.toolStripProgressBar1.Visible = true; SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance; if ((Progress > 0) && (ProgressMax > 0)) { this.toolStripProgressBar1.Maximum = ProgressMax; this.toolStripProgressBar1.Step = Progress; this.toolStripProgressBar1.PerformStep(); } else if (wb.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { this.toolStripProgressBar1.Value = 0; this.toolStripProgressBar1.Visible = false; } }
private SHDocVw.WebBrowser CreateNewWebBrowser() { //此版本不支持多Tab页,如果支持多Tab页需要对webbrowser重新进行封装,第一期暂不做了 this.toolSource.Enabled = true; System.Windows.Forms.WebBrowser TmpWebBrowser = new System.Windows.Forms.WebBrowser(); if (this.WebBrowserTab.TabPages.Count == 1 && this.WebBrowserTab.TabPages[0].Controls.Count == 0) { //表示第一次启动打开网页,则在默认的分页中增加webbrowser,不需要增加tab页 this.WebBrowserTab.TabPages[0].Controls.Add(TmpWebBrowser); } else { //TabPage newTabPage = new TabPage(); //((WebBrowserTag)TmpWebBrowser.Tag).TabIndex = this.WebBrowserTab.TabPages.Count + 1; //newTabPage.Controls.Add(TmpWebBrowser); //this.WebBrowserTab.TabPages.Add(newTabPage); //this.WebBrowserTab.SelectedTab = newTabPage; this.WebBrowserTab.TabPages[0].Controls.Clear(); this.WebBrowserTab.TabPages[0].Controls.Add(TmpWebBrowser); } TmpWebBrowser.Dock = DockStyle.Fill; SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)TmpWebBrowser.ActiveXInstance; wb.CommandStateChange += new SHDocVw.DWebBrowserEvents2_CommandStateChangeEventHandler(this.wb_CommandStateChange); wb.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.wb_BeforeNavigate2); wb.ProgressChange += new SHDocVw.DWebBrowserEvents2_ProgressChangeEventHandler(this.wb_ProgressChange); wb.StatusTextChange += new SHDocVw.DWebBrowserEvents2_StatusTextChangeEventHandler(this.wb_StatusTextChange); wb.NavigateError += new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(this.wb_NavigateError); wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.wb_NavigateComplete2); wb.TitleChange += new SHDocVw.DWebBrowserEvents2_TitleChangeEventHandler(this.wb_TitleChange); wb.DocumentComplete += new SHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.wb_DocumentComplete); wb.NewWindow2 += new SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(this.wb_NewWindow2); return(wb); }
public int SetSite(object site) { if (site != null) { webBrowser = (SHDocVw.WebBrowser)site; webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler( this.OnDocumentComplete); } else { webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler( this.OnDocumentComplete); webBrowser = null; } return 0; }
private void Main_Load(object sender, EventArgs e) { this.pictureBox1.Image = Properties.Resources.ResourceManager.GetObject("min") as Image; this.pictureBox1.Width = this.pictureBox1.Image.Width; this.pictureBox1.Height = this.pictureBox1.Image.Height; this.pictureBox2.Image = Properties.Resources.ResourceManager.GetObject("close") as Image; this.pictureBox2.Width = this.pictureBox2.Image.Width; this.pictureBox2.Height = this.pictureBox2.Image.Height; //this.pictureBox1.MouseHover+=pictureBox1_MouseHover; //this.pictureBox1.MouseLeave+=pictureBox1_MouseLeave; this.panel1.BackgroundImage = Properties.Resources.ResourceManager.GetObject("title") as Image; if (!CheckNewVersion()) { if (MessageBox.Show("检查到有新版本,需要更新吗?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { if (File.Exists((Application.StartupPath + "\\Beauty.Update.exe"))) { System.Diagnostics.Process.Start(Application.StartupPath + "\\Beauty.Update.exe"); } else { MessageBox.Show("找不到更新程序文件"); } } } this.webBrowser1.Navigate(domain + "/home/index?uid=" + user.Userid); this.webBrowser2.Navigate("http://www.meilishuo.com/user/login"); this.webBrowser2.DocumentCompleted += webBrowser2_DocumentCompleted; this.webBrowser2.Navigating += webBrowser2_Navigating; SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)webBrowser2.ActiveXInstance; this.webBrowser2.Navigated += webBrowser2_Navigated; this.webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; SetIsStartUp(); activethread.Start(); noticethread.Start(); systemnoticethread.Start(); this.Load += Main_Load; //this.CreateGraphics().DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1)); //this.Refresh(); }
//마지막 탭으로 ie 변경 private void changeIeTab() { // Console.WriteLine("changeIeTab 시작"); log.Debug("changeIeTab Start"); ShellWindows allBrowsers = new ShellWindows(); for (int i = allBrowsers.Count - 1; i >= 0; i--) { if (allBrowsers.Item(i) != null && !string.IsNullOrEmpty(((SHDocVw.InternetExplorer)allBrowsers.Item(i)).LocationURL)) { ie = (InternetExplorer)allBrowsers.Item(i); webBrowser = (SHDocVw.WebBrowser)ie; ie.Wait(); // Console.WriteLine("changeIeTab 끝"); log.Debug("changeIeTab End"); return; } } log.Debug("changeIeTab 반환없이 End"); }
private HTMLDocument GetDocument() { try { SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)((System.Windows.Forms.WebBrowser) this.WebBrowserTab.TabPages[0].Controls[0]).ActiveXInstance; wb.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(wb_DocumentComplete); HTMLDocument htm = (HTMLDocument)wb.Document; //if (wb.ReadyState.==WebBrowserReadyState.Complete) //{ //} // iw MessageBox.Show(wb.ReadyState.ToString()); return(htm); } catch (System.Exception ex) { throw (ex); } }
private void FrmBrowserAW_Load(object sender, EventArgs e) { try { //timer.Enabled = true; //timer.Interval = 1000; //timer.Tick += timer_Tick; search = true; Share.SuppressWininetBehavior(); webBrowser1.Navigate("http://om.tencent.com/attendances/check_out/"); wb = webBrowser1.ActiveXInstance as SHDocVw.WebBrowser; wb.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); //waitwebCompleted(); //SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser; //wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private void button1_Click(object sender, EventArgs e) { keywordCollection.Clear(); loadKeyWord(); int loopCnt = Convert.ToInt32(broswerNumTXT.Text.Trim()); for (int index = 0; index < loopCnt; index++) { //int for loop string keyWord = getRandKeyWord(); if (keyWord == "") { continue; } //changeVPN(); object o = null; SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass(); SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)ie; IntPtr wbHWND = (IntPtr)wb.HWND; wb.Visible = true; //wb.FullScreen = true; //ShowWindow(wbHWND, SW_MAXIMIZE); //Do anything else with the window here that you wish wb.Navigate("http://www.taobao.com/", ref o, ref o, ref o, ref o); while (wb.Busy) { Thread.Sleep(100); } //ShowWindow(wbHWND, SW_MAXIMIZE); searchBroswer(wb, keyWord); wb.Quit(); } }
private void capturePic_Click2(object sender, EventArgs e) { string captureLocation = @"D:\IECapt\IECapt.exe"; SHDocVw.WebBrowser m_browser = null; //get browser SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // string filename; foreach (SHDocVw.WebBrowser ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { m_browser = ie; break; } } Process p = Process.Start(captureLocation, "--url=" + m_browser.LocationURL + " --out=" + @"c:\\IECapture\Captured_" + DateTime.Now.ToString("yyyy-mm-dd") + ".jpg"); p.WaitForExit(); }
private void wb_NewWindow2(ref object ppDisp, ref bool Cancel) { SHDocVw.WebBrowser _axWebBrowser = CreateNewWebBrowser(); ppDisp = _axWebBrowser.Application; _axWebBrowser.RegisterAsBrowser = true; }
void webBrowser_NavigateComplete2(object pDisp, ref object URL) { // If the site or url is null, do not continue if (pDisp == null || URL == null) { return; } // Access both the web browser object and the url passed // to this event handler SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)pDisp; // 웹브라우저가 페이지 이동 중에 만드는 웹브라우저 메소드(webBrowser와 browser은 페이지 이동 중에 딱 한 번 일치한다.) // 이를 이용해 한번만 검사하도록 변경한게 if (webBrowser.LocationURL.Equals(browser.LocationURL)) string url = URL.ToString(); int rating = 0; IHTMLDocument2 document = null; if (webBrowser.LocationURL.Equals(browser.LocationURL) && check) // 현재 이동하는 페이지가 사용자가 URL창에 입력한 주소와 동일한지 체크 // 혹은 이미 체크했는지 체크(안하면 차단 페이지에 못들어가고 // 원래 URL -> 차단 페이지의 버튼 누르면 들어가지는 URL(php 페이지의 burl)의 변수로 들어감 -> 또들어감 -> 또들어감 의 반복 { /* 6월 18~19일 내용 수정 * 차단 php 페이지 띄우도록 변경 */ // Grab the document object off of the Web Browser control document = (IHTMLDocument2)webBrowser.Document; if (document == null) { return; } rating = DBConnector.GetSiteInfo(url); if (rating > 0) { check = false; } } if (rating <= 0) { // This is Safe Site. // Pass the current URL to the broker PassUrlToBroker(url); } else if (rating >= 1 && rating <= 25) { // 낮은 점수의 페이지에 접근하면 화면 오른쪽 하단에서 메신저 // 알림 올라오듯이 만드려고 한거, 근데 작동안함, 하지만 에러가 아예 없어 뭐가 문제인지 파악불가 // This is Reported Site. But Not Blocked Site // Pass the current URL to the broker TaskbarNotifier tNotify = new TaskbarNotifier(); tNotify.SetBackgroundBitmap("popup.bmp", Color.FromArgb(0, 0, 0)); tNotify.SetCloseBitmap("close.bmp", Color.FromArgb(0, 0, 0), new Point(127, 8)); tNotify.TitleRectangle = new Rectangle(40, 9, 70, 25); tNotify.ContentRectangle = new Rectangle(8, 41, 133, 68); tNotify.TitleClick += new EventHandler(TitleClick); tNotify.ContentClick += new EventHandler(ContentClick); tNotify.CloseClick += new EventHandler(CloseClick); tNotify.Show("경고", "신고된 페이지입니다. 주의하여 사용해주세요", 100, 300, 100); // 수정이 필요하면 이 위에까지 잘라내고 새로 넣어도 무방함. 아래는 페이지를 띄워주는 코드이므로 안됨 PassUrlToBroker(url); } else if (rating >= 26 && rating <= 75) { // This is Reported Site. // Move to weak Blocked page // 점수가 그냥 높은 수준일 때 차단 페이지로 이동. // webBrowser.LocationURL : URL을 직접 입력, 혹은 Navigate2로 이동할 때 기록되는 페이지 // BeforeURL : 이전 주소 browser.Stop(); browser.Navigate2("http://siteblocker.iptime.org/blocked.php?lvl=0&url=" + webBrowser.LocationURL + "&burl=" + BeforeURL, true); } else if (rating >= 76 && rating <= 100) { // This is Reported Site. // Move to String Blocked Page browser.Stop(); browser.Navigate2("http://siteblocker.iptime.org/blocked.php?lvl=1&url=" + webBrowser.LocationURL + "&burl=" + BeforeURL, true); } rating = 0; }
private void button1_Click(object sender, EventArgs e) { ////// Create a new instance of the Firefox driver. ////// Notice that the remainder of the code relies on the interface, ////// not the implementation. ////// Further note that other drivers (InternetExplorerDriver, ////// ChromeDriver, etc.) will require further configuration ////// before this example will work. See the wiki pages for the ////// individual drivers at http://code.google.com/p/selenium/wiki ////// for further information. ////IWebDriver driver = new FirefoxDriver(); //////Notice navigation is slightly different than the Java version //////This is because 'get' is a keyword in C# ////driver.Navigate().GoToUrl("http://www.google.com/"); ////// Find the text input element by its name ////IWebElement query = driver.FindElement(By.Name("q")); ////// Enter something to search for ////query.SendKeys("Cheese"); ////// Now submit the form. WebDriver will find the form for us from the element ////query.Submit(); ////// Google's search is rendered dynamically with JavaScript. ////// Wait for the page to load, timeout after 10 seconds ////WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); ////wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); }); ////// Should see: "Cheese - Google Search" ////System.Console.WriteLine("Page title is: " + driver.Title); //////Close the browser ////driver.Quit(); //string IELocation = @"%ProgramFiles%\Internet Explorer\iexplore.exe"; //IELocation = System.Environment.ExpandEnvironmentVariables(IELocation); //Console.WriteLine("Launching IE "); //Process p = Process.Start(IELocation, @"http://www.baidu.com"); //Thread.Sleep(3000); //Console.WriteLine("Attaching to IE ... "); //InternetExplorer ie = null; //string ieWindowName = "空白页"; //if (p != null) //{ // //Console.WriteLine("Process handle is: " + p.MainWindowHandle.ToString()); // SHDocVw.ShellWindows allBrowsers = new ShellWindowsClass(); // Console.WriteLine("Number of active IEs :" + allBrowsers.Count.ToString()); // if (allBrowsers.Count != 0) // { // SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); // foreach (SHDocVw.InternetExplorer ieVW in shellWindows) // { // // 判斷視窗是否為 iexplore // if (Path.GetFileNameWithoutExtension(ieVW.FullName).ToLower().Equals("iexplore")) // { // ie = ieVW; // break; // } // } // //for (int i = 0; i < allBrowsers.Count; i++) // //{ // // //IWebBrowser2 iwb2 = allBrowsers.Item(i) as IWebBrowser2; // // InternetExplorer eitem = (InternetExplorer)allBrowsers.Item(i); // // int l = eitem.HWND; // // int j = 0; // // j++; // // if (eitem.HWND == (int)p.MainWindowHandle.ToInt32()) // // { // // ie = eitem; // // break; // // } // //} // } // else // throw new Exception("Faul to find IE"); //} //else // throw new Exception("Fail to launch IE"); ////var ie = new SHDocVw.InternetExplorer(); ////ie.Visible = true; ////object o = null; ////Console.WriteLine("打开百度首页..."); ////ie.Navigate(@"http://www.baidu.com", ref o, ref o, ref o, ref o); //Thread.Sleep(1000); //HTMLDocument doc = (HTMLDocument)ie.Document; //Console.WriteLine("网站标题:" + doc.title); //Console.WriteLine("输入搜索关键字:飞苔博客"); //var keyEle = doc.getElementById("kw"); //keyEle.setAttribute("value", "飞苔博客", 0); //Console.WriteLine("点击[百度一下]按钮,进行搜索"); //var btnSubmit = doc.getElementById("su"); //btnSubmit.click(); //Thread.Sleep(500); //Console.WriteLine("网站标题:" + doc.title); ////var relatedSearchResultEle = doc.getElementsByTagName("SPAN").Cast<ihtmlelement>().Where(ele => ele.className == "nums").FirstOrDefault(); //Console.WriteLine("百度相关搜索结果:"); //p.Close(); ////Console.WriteLine(relatedSearchResultEle.innerHTML); object o = null; SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass(); SHDocVw.WebBrowser wb = (SHDocVw.WebBrowser)ie; wb.Visible = true; wb.FullScreen = true; //Do anything else with the window here that you wish wb.Navigate("http://www.taobao.com/", ref o, ref o, ref o, ref o); while (wb.Busy) { Thread.Sleep(100); } HTMLDocument document = ((HTMLDocument)wb.Document); IHTMLElement element = document.getElementById("q"); HTMLInputElementClass email = (HTMLInputElementClass)element; email.value = "包装盒子"; var elements = document.getElementsByTagName("button"); foreach (HTMLButtonElementClass element1 in elements) { // If there's more than one button, you can check the //element.InnerHTML to see if it's the one you want if (element1.innerHTML.Contains("搜 索")) { element1.click(); } } //for (int i = 0; i < count; i++) //{ // //去抓標籤名字有a的,像是連結<a href=xx>這種 // //奇怪的是這個方法如果要抓一些標籤都抓不到,像是<td><tr>那些=.= // //所以那些我是用另外的方法抓的,等下會講 // if (document.all[i].TagName.ToLower().Equals("button")) // { // //GetAttribute就是去取得標籤的屬性的內容,例: // //<a href ="我是屬性的內容" target=_blank>,不過有些屬性取不到,像是class // if (doc.All[i].GetAttribute("type").Contains("submit")) // { //InnerText就是取得標籤中間的內容,<標籤>內容</標籤> // //richTextContent1.AppendText(doc.All[i].InnerText); // //richTextContent1.AppendText(doc.All[i].GetAttribute("href")); // //richTextContent1.AppendText(Environment.NewLine); // ////另外這個函式可以去更改HTML裡面屬性的內容 // //XXX.SetAttribute("value", "Hello"); // int j = i; // j++; // } // } //} IHTMLElement search = document.getElementById(@"tag:BUTTON&value:搜 索"); HTMLButtonElementClass searchEle = (HTMLButtonElementClass)search; searchEle.click(); //email = null; //element = document.getElementById("Passwd"); //HTMLInputElementClass pass = (HTMLInputElementClass)element; //pass.value = "pass"; //pass = null; //element = document.getElementById("signIn"); //HTMLInputElementClass subm = (HTMLInputElementClass)element; //subm.click(); //subm = null; //while (wb.Busy) { Thread.Sleep(100); } //wb.Navigate("https://adwords.google.co.uk/o/Targeting/Explorer?", ref o, ref o, ref o, ref o); //while (wb.Busy) { Thread.Sleep(100); } //string connString = "SERVER=localhost;" + // "DATABASE=test;" + // "UID=root;"; ////create your mySQL connection //MySqlConnection cnMySQL = new MySqlConnection(connString); ////create your mySql command object //MySqlCommand cmdMySQL = cnMySQL.CreateCommand(); ////create your mySQL reeader object //MySqlDataReader reader; ////open the mySQL connection //cnMySQL.Open(); //int j = 1; //cmdMySQL.CommandText = "SELECT * FROM `emails1` WHERE `send`>'" + j + "' order by `send` asc limit 0,1"; //reader = cmdMySQL.ExecuteReader(); //reader.Read(); //j = (int)reader.GetValue(1); HTMLElementCollection col = default(HTMLElementCollection); document = ((HTMLDocument)wb.Document); col = (HTMLElementCollection)document.getElementsByTagName("textarea"); //the error happens here in this typecast //Console.WriteLine(j); wb.Quit(); }