zoukankan      html  css  js  c++  java
  • 遍历页面元素

    代码
    uses
      shdocvw, Mshtml, ActiveX;

    function GetIEFromHWND(WHandle: HWND; var IE: IWebbrowser2): HRESULT;
    var
      hInst: HWND;
      lRes: Cardinal;
      MSG: Integer;
      pDoc: IHTMLDocument2;
      ObjectFromLresult: TObjectFromLresult;
    begin
       hInst :
    = LoadLibrary('Oleacc.dll');
       @ObjectFromLresult :
    = GetProcAddress(hInst, 'ObjectFromLresult');
       
    if @ObjectFromLresult <> nil then
       
    begin
         
    try
           MSG :
    = RegisterWindowMessage('WM_HTML_GETOBJECT');
           SendMessageTimeOut(WHandle, MSG, 
    00, SMTO_ABORTIFHUNG, 1000, lRes);
           Result :
    = ObjectFromLresult(lRes, IHTMLDocument2, 0, pDoc);
           
    if Result = S_OK then
             (pDoc.parentWindow 
    as IServiceprovider).QueryService(IWebbrowserApp, IWebbrowser2, IE);
         
    finally
           FreeLibrary(hInst);
         
    end;
       
    end;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    var
      I: IWebbrowser2;
      Document: IHtmlDocument2;
      HtmlElement: IHtmlElement;
      All: IHtmlElementCollection;
      J: Integer;
    begin
      GetIEFromHWND(
    66000, I); // 66000是我自己测试用的句柄
      Document :
    = I.Document as IHtmlDocument2;
      
    if Assigned(Document) then
      
    begin
        All :
    = Document.all;
        
    for J := 0 to All.length - 1 do
        
    begin
          HtmlElement :
    = All.item(J, 0as IhtmlElement;
          Memo1.Lines.Add(IntToStr(J) 
    + ' ' + HTmlElement.innerHTML);
        
    end;
      
    end;  
      Caption :
    = i.LocationURL;
    end;
  • 相关阅读:
    个人介绍
    对软件工程课程的希望
    对这门课程的的希望和目标
    关于sql server profiler 监控工具的使用
    关于eclipse常用的一些快捷键
    后台页面中发现的一点问题总结
    电脑端手机模拟器软件
    关于.net后台的异步刷新的问题
    Excle中的使用小技巧
    关于.net里面的静态html页面和接口组合使用的网站
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1762033.html
Copyright © 2011-2022 走看看