Delphi 解析HTML

procedure TForm1.btnphClick(Sender: TObject);
var
  Document: IHTMLDocument2;
  FTableCollection, tempCoc: IHTMLElementCollection;
  table: IHTMLTABLE;
  TableRow: IHTMLTableRow;
  elmt: IHTMLEleMent;
  I, J, K: integer;
  str: string;
begin
  Document := WebBrowser1.Document as IHTMLDocument2;
  FTableCollection := Document.all;
  FTableCollection.Length; //
  FTableCollection.item(1, 0);
  FTableCollection := Document.all.tags(table) as IHTMLElementCollection;
  for I := 0 to FTableCollection.Length - 1 do
  begin
    table := FTableCollection.item(I, 0) as IHTMLTABLE;  //题数
    for J := 0 to table.rows.Length - 1 do
    begin
      TableRow := (table.rows.item(J, 0) as IHTMLTableRow); //每道题信息
      str := ‘‘;
      for K := 0 to TableRow.cells.Length - 1 do
      begin
        elmt := TableRow.cells.item(K, 0) as IHTMLEleMent;
        str := str + elmt.innerText + #9;
      end;
      str := StringReplace(str, ‘‘#$D#$A‘‘, ‘‘, [rfReplaceAll]);
      Memo3.Lines.Add(str);
      Memo3.Lines.Add(------------------------------------------);
    end;
  end;
end;

  URL := ‘http://bbs.csdn.net/forums/Delphi‘;
  WebBrowser1.Navigate(URL);

下面是一行tablerow的数据,可以分解出来,<td><td>之间是一个cell列。

如何解析第一列的href、class之间的3个数据呢,?、delphi7 滚动条颜色、VCL组件开发及应用

 

          <tr>
    <td class="title">
      <strong class="green"></strong>
      <a href="/topics/390861446" target="_blank" title="delphi7 滚动条颜色">delphi7 滚动条颜色</a>
      <span class="forum_link">[<span class="parent"><a href="/forums/Delphi">Delphi</a></span> <a href="/forums/DelphiVCL">VCL组件开发及应用</a>]</span>
    </td>
    <td class="tc">20</td>
    <td class="tc">
      <a href="http://my.csdn.net/u010745617" rel="nofollow" target="_blank">u010745617</a><br />
      <span class="time">08-15 16:25</span></td>
    <td class="tc">1</td>
    <td class="tc">
      <a href="http://my.csdn.net/NongCunGongLu" rel="nofollow" target="_blank">NongCunGongLu</a><br />
      <span class="time">08-17 13:41</span>
    </td>
    <td class="tc">
      <a href="/topics/390861446/close" target="_blank">管理</a>
    </td>
  </tr>

 

Delphi 解析HTML,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。