//引用 Windows/system32/Shell32.dll
//引用COM組件 shdocvw.dll (Microsoft Internet Controls)
//引用COM組件 mshtml.tlb (Microsoft HTML Object Library)html
//系統進程中獲取IE全部已打開的Tab標籤
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
SHDocVw.InternetExplorer wbBrowser = null;
string filename;
foreach (SHDocVw.InternetExplorer ie in shellWindows){filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();//當ie已打開多個標籤頁時可取得每一個標籤頁的Title
var ln = ie.LocationName;if (filename.Equals("iexplore")){wbBrowser = ie;}}
//可反取系統句柄
wbBrowser.HWND.ToString()//控制導航到指定網址
wbBrowser.Navigate("http://www.rediff.com", null, null, null, null);while (!wbBrowser.Busy)
{break;
}//下載完成事件
wbBrowser.DocumentCompletewbBrowser.DownloadComplete//獲取網頁內容
var HTMLDoc = (HTMLDocument)wbBrowser.Document;//獲取dom元素
//HTMLDoc.elementFromPoint //經過 x,y座標獲取元素,網頁內容區域做爲起始點計算
//HTMLDoc.getElementsByName //經過標籤name屬性獲取元素 返回值爲元素數組
var iHTMLEle = HTMLDoc.getElementById("id2"); //經過標籤id屬性獲取元素//設置元素值
iHTMLEle.setAttribute("value", "jacoblai");//從body域中過濾元素
IHTMLDocument2 doc = (IHTMLDocument2)HTMLDoc.body.all;if (null != doc){foreach (IHTMLElement element in doc.all){if (element.id == "wrapper"){HTMLDivElement container = element as HTMLDivElement;
dynamic dd = container;string result = dd.IHTMLElement_innerHTML;
// You get ANY member of HTMLDivElementClass
break;
}}}