2010-10-30 15 views
1

我想在Visual Studio中創建一個C#中的程序,它將在Internet Explorer中獲取當前打開(或選定或全部)選項卡的HTML源代碼8 /(首選)9.我厭倦了通過 - 瀏覽器 - >查看源代碼,alt + a,alt + c,程序 - > alt + v 任何人都有一個想法如何解決它?如何獲得IE8/9的活動選項卡html源碼C#

回答

2

嗯,這不是一個簡單的解決方案,我認爲也許你應該繼續複製和粘貼。無論如何,這是我發現網上衝浪:(http://www.experts-exchange.com/Microsoft/Development/Q_23767759.html

{ // used spy++ to get the names of these guys 
      // get the handle to the IE toolbar 
      childHandle = FindWindowEx(IEwindowHandle, IntPtr.Zero, "WorkerW", IntPtr.Zero); 
      if (childHandle != IntPtr.Zero) 
      { 
       //get the handle to the address bar on IE 
       childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ReBarWindow32", IntPtr.Zero); 
       if (childHandle != IntPtr.Zero) 
       { 
        // get a handle to comboBoxEx32 
        childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBoxEx32", IntPtr.Zero); 
        if (childHandle != IntPtr.Zero) 
        { 
         // get a handle to combo box 
         childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", IntPtr.Zero); 
         if (childHandle != IntPtr.Zero) 
         { 
          //get handle to edit 
          childHandle = FindWindowEx(childHandle, IntPtr.Zero, "Edit", IntPtr.Zero); 
          if (childHandle != IntPtr.Zero) 
          { 
           // now to get the URL we need to get the Text - but first get the length of the URL 
           int length = SendMessage(childHandle, WM_GETTEXTLENGTH, 0, 0); 
           length += 1; // because the length returned above included 0 
           StringBuilder text = new StringBuilder(length); // need stringbuilder - not string 
           int hr = SendMessage(childHandle, WM_GETTEXT, length, text); // get the URL 
           strURL = text.ToString(); 
          } 
         } 
        } 
       } 

現在你已經訪問的URL,發送一個HTTP GET請求,你會得到以純文本的網站源。

+0

這是一段非常好的代碼 - 所以如果你可以問瀏覽器一個網址,爲什麼不問它的來源? – 2010-10-30 14:32:26

+0

更多,即分爲幀選項卡(從間諜++) - 每個窗口框架選項卡有一個窗口TabWindowsClass其中有一個窗口外殼DocObject視圖有一個窗口Internet Explorer_Server – 2010-10-30 14:35:45

+0

@Miszka:我能找到的最好的使用稱爲帶對象。 http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/415f8b61-7db4-48ab-ab5c-71721afac718哪個是在CodeProject上承載的...哪幾個小時下來。儘可能檢查一下。希望你做到。並讓我知道你是否做到了。 – Kamyar 2010-10-30 15:21:03

相關問題