zoukankan      html  css  js  c++  java
  • HTML网页Table解析

    procedure TForm27.Button1Click(Sender: TObject);
    var
      doc2: IHTMLDocument2;
      doc3: IHTMLDocument3;
      itableCollection, emtCollection: IHTMLElementCollection;
      itable: IHTMLTABLE;
      emt: IHTMLElement;
      tabrow: IHTMLTableRow;
      tabsec: IHTMLTableSection;
      I, J, K: integer;
      sid, s1, s2, s3, s4, s5, sText: string;
    begin
      ListBox1.Clear;
      WebBrowser1.Navigate('http://zx.caipiao.163.com/trend/11xuan5/?beginPeriod=14092901&endPeriod=14100875&selectDate=4');
      while WebBrowser1.Busy do
        Application.ProcessMessages;
    
      doc2 := self.WebBrowser1.Document as IHTMLDocument2;
      doc3 := WebBrowser1.Document as IHTMLDocument3;
      itableCollection := doc2.all.tags('table') as IHTMLElementCollection;
    
      for I := 0 to itableCollection.Length - 1 do
      begin
        itable := itableCollection.item(I, 0) as IHTMLTABLE;
        emt := itable as IHTMLElement;
    
        if emt.id = 'chartsTable' then
        begin
          emt := itable.tBodies.item(1, 0) as IHTMLElement; // tbody cpdata
          tabsec := emt as IHTMLTableSection;
          tabsec.rows.Length;
    
          for J := 0 to tabsec.rows.Length - 1 do
          begin
            tabrow := tabsec.rows.item(J, 0) as IHTMLTableRow;
            if tabrow.cells.Length < 10 then
              Continue;
            sid := (tabrow.cells.item(0, 0) as IHTMLElement).innerText; // 14100718
            s1 := (tabrow.cells.item(2, 0) as IHTMLElement).innerText; // 01
            s2 := (tabrow.cells.item(3, 0) as IHTMLElement).innerText; // 02
            s3 := (tabrow.cells.item(4, 0) as IHTMLElement).innerText; // 03
            s4 := (tabrow.cells.item(5, 0) as IHTMLElement).innerText; // 04
            s5 := (tabrow.cells.item(6, 0) as IHTMLElement).innerText; // 05
            sText := Format('%s %s %s %s %s %s', [sid, s1, s2, s3, s4, s5]);
            ListBox1.Items.Add(sText);
          end;
        end;
      end;
    end;
  • 相关阅读:
    SpringBoot与quartz集成
    SpringBoot 中使用 @Valid 注解 + Exception 全局处理器优雅处理参数验证
    搭建Redis集群和MySQL主从同步
    scanf_s读取键盘输入字符串失败
    含有通配符*的字符匹配(C语言)
    人之患
    TCP socket编程记录(C语言)
    程序变量命名规范(个人)
    h lib dll文件相关部分
    关于inet_ntop、inet_pton中的n和p分别代表的意义
  • 原文地址:https://www.cnblogs.com/cb168/p/4012540.html
Copyright © 2011-2022 走看看