//引用 Windows/system32/Shell32.dll
//引用COM组件 shdocvw.dll (Microsoft Internet Controls)
//引用COM组件 mshtml.tlb (Microsoft HTML Object Library)
//系统进程中获取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已打开多个标签页时可取得每个标签页的Titlevar 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 HTMLDivElementClassbreak;}}}
时间: 2024-10-11 10:54:09