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;
  • 相关阅读:
    死信队列消息原因排查
    MQ中间件死信队列深度不断增加问题解决案例
    DB2 57016报错的解决办法(表状态不正常,导致表无法操作)
    万门大学--童哲
    eclipse jvm配置
    weblogic threadpool has stuck threads
    8-10 ObserveableCommand演示
    8-9 四种执行方式区别讲解
    8-8 toObserve两种形态演示
    8-7 Observe两种形态演示
  • 原文地址:https://www.cnblogs.com/chengxin1982/p/1762033.html
Copyright © 2011-2022 走看看