IE外挂

//引用 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.DocumentComplete 
wbBrowser.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; 
                   } 
               } 
           } 
posted @   黎东海  阅读(498)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
历史上的今天:
2015-01-22 树莓派做coolpy服务器
点击右上角即可分享
微信分享提示