Delphi 解析HTML

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   strong   資料   

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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.