zoukankan      html  css  js  c++  java
  • Delphi TWebBrowser[8] 访问网页中的表格

    Delphi TWebBrowser[8] 访问网页中的表格

    use MSHTML;
    
    function GetHtmlTableCell(aTable: IHTMLTable; aRow, aCol: Integer): IHTMLElement;
    var
      Row: IHTMLTableRow;
    
    begin
      Result := nil;
      if aTable = nil then Exit;
      if aTable.rows = nil then Exit;
      Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
      if Row = nil then Exit;
      Result := Row.cells.item(aCol, aCol) as IHTMLElement;
    end;
    
    function GetHtmlTable(aDoc: IHTMLDocument2; aIndex: Integer): IHTMLTable;
    var
      list: IHTMLElementCollection;
    begin
      Result := nil;
      if aDoc = nil then Exit;
      if aDoc.all = nil then Exit;
      list := aDoc.all.tags('table') as IHTMLElementCollection;
      if list = nil then Exit;
      Result := list.item(aIndex,aIndex) as IHTMLTable;
    end;
    
    function GetWebBrowserHtmlTableCellText(const AWebBrowser: TWebBrowser;
      const TableIndex, RowIndex, ColIndex: Integer;
      var ResValue: string): Boolean;
    var
      Docintf: IHTMLDocument2;
      tblintf: IHTMLTable;
      node: IHTMLElement;
    begin
      ResValue := '';
      docintf := AWebBrowser.Document as IHTMLDocument2;
      tblintf := GetHtmlTable(docintf, TableIndex);
      node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);
      Result := node <> nil;
      if Result then
        ResValue := Trim(node.innerText);
    end;
    
    function GetHtmlTableRowHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;
    var
      Row: IHTMLTableRow;
    begin
      Result := nil;
      if aTable = nil then Exit;
      if aTable.rows = nil then Exit;
      Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
      if Row = nil then Exit;
      Result := Row as IHTMLElement;
    end;
    
    function GetWebBrowserHtmlTableCellHtml(const AWebBrowser: TWebBrowser;
      const TableIndex, RowIndex, ColIndex: Integer;
      var ResValue: string): Boolean;
    var
      Docintf: IHTMLDocument2;
      tblintf: IHTMLTable;
      node: IHTMLElement;
    begin
      ResValue := '';
      docintf := AWebBrowser.Document as IHTMLDocument2;
      tblintf := GetHtmlTable(docintf, TableIndex);
      node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);
      Result := node <> nil;
      if Result then
        ResValue := Trim(node.innerHTML);
    end;
    
    function GeHtmlTableHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;
    var
      Row: IHTMLTableRow;
    begin
      Result := nil;
      if aTable = nil then Exit;
      if aTable.rows = nil then Exit;
      Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
      if Row = nil then Exit;
      Result := Row as IHTMLElement;
    end;
    
    function GetWebBrowserHtmlTableHtml(const AWebBrowser: TWebBrowser;
      const TableIndex, RowIndex: Integer;
      var ResValue: string): Boolean;
    var
      Docintf: IHTMLDocument2;
      tblintf: IHTMLTable;
      node: IHTMLElement;
    begin
      ResValue := '';
      docintf := AWebBrowser.Document as IHTMLDocument2;
      tblintf := GetHtmlTable(docintf, TableIndex);
      node := GeHtmlTableHtml(tblintf, RowIndex);
      Result := node <> nil;
      if Result then
        ResValue := node.innerHtml;
    end;
    

      

    创建时间:2020.11.23  更新时间:

    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你所有帮助,谢谢!
  • 相关阅读:
    NHibernate 入门必看——NHibernate Made Simple
    ASP.NET 的多线程
    asp.net 禁止用户二次登录(转)
    marquee标记用法及在asp.net中的应用(转)
    解决Visual Studio 2005显示中文乱码(zhuan)
    ms sql 触发器( 转)
    Asp.net 页面导航的几种方法与比较
    ASP.NET1.1(VB):DataGrid中"加入序号列"和"截取定长字符串追加'...
    解决“Internet Explorer 无法打开 Internet站点已终止操作”问题(转)
    ASP.NET 2.0的页面指令集(转)
  • 原文地址:https://www.cnblogs.com/guorongtao/p/14022875.html
Copyright © 2011-2022 走看看