标签:for with net 控制 attribute intern while system new
//引用 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已打开多个标签页时可取得每个标签页的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;
}}}
标签:for with net 控制 attribute intern while system new
原文地址:http://www.cnblogs.com/jacle169/p/6340752.html