uses mshtml;

IHTMLEleMent.ID;

IHTMLEleMent.tagName;

IHTMLEleMent.title;
elmt._className;
elmt.getAttribute('anchor', 0);
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(, );
FTableCollection := Document.all.tags('table') as IHTMLElementCollection;
for I := to FTableCollection.Length - do
begin
table := FTableCollection.item(I, ) as IHTMLTABLE; //题数
for J := to table.rows.Length - do
begin
TableRow := (table.rows.item(J, ) as IHTMLTableRow); //每道题信息
str := '';
for K := to TableRow.cells.Length - do
begin
elmt := TableRow.cells.item(K, ) as IHTMLEleMent;
str := str + elmt.innerText + #;
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>
    <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这一部分IHTMLEleMent当作IHTMLElementCollection解析就可以了,tagName,getAttribute('href',0),title,_className都可以获得正确的值,是6个集合元素。

       tempCoc := elmt.all as IHTMLElementCollection;
if (tempCoc.Length = ) then
begin
for q := to tempCoc.Length - do
begin
emt2 := tempCoc.item(q, ) as IHTMLEleMent;
if emt2.tagName = 'STRONG' then
s2 := emt2.innerText
else if emt2.tagName = 'A' then
begin
s2 := emt2.getAttribute('href',);
s2 := emt2.title;
s2 := emt2.innerText;
end
else if emt2.tagName = 'SPAN' then
begin
emt2.tagName;
emt2._className;
emt2.title;
emt2.innerText;
end;
end;
end;

elmt: IHTMLEleMent;

elmt := (WebBrowser1.Document as ihtmldocument3).getElementById('idbtn001');

getElementsByName

getElementById

getElementsByTagName

doc2: IHTMLDocument2;
doc3: IHTMLDocument3;

doc2.forms.item('form1',0) as IHTMLFormElement;//取form1的表单

elmt := (WebBrowser1.Document as IHTMLDocument3).getElementById('divfirstID');//通过ID取得某个节点

elmt := ((elmt.children as IHTMLElementCollection).item(, )) as IHTMLEleMent;//子节点
elmt := ((elmt.children as IHTMLElementCollection).item(, )) as IHTMLEleMent;//子节点
elmt := ((elmt.children as IHTMLElementCollection).item(, )) as IHTMLEleMent;//子节点
elmt := ((elmt.children as IHTMLElementCollection).item(, )) as IHTMLEleMent;//子节点里的第3个子节点
elmt := ((elmt.children as IHTMLElementCollection).item(, )) as IHTMLEleMent;//子节点

Delphi 解析HTML的更多相关文章

  1. DELPHI解析JSON格式化的日期

    DELPHI解析JSON格式化的日期 json返回的日期是 /Date(1560355200000)/ 这样的格式. 这个1560355200000,是指1970年以后的秒数. DELPHI如何解析这 ...

  2. delphi 解析Json格式(转自:http://blog.csdn.net/jayqiang/article/details/7066824)

    SuperObject 是开源的 Delphi 的 JSON 工具包,可生成 JSON 数据以及进行 JSON 解析. unit Unit6; interface uses Windows, Mess ...

  3. Delphi解析修改Json文件,基于superobject.pas(ISuperObject)

    在经过一系列的波折后,还是觉得delphi读取并修改json文件来的方便: 在网络上找到一个delphi的三方库ISuperObject,添加到项目后直接引用就行: 下载地址 ISuperObject ...

  4. 让delphi解析chrome扩展的native应用

    chrome浏览器自从去年以来逐步去掉了对浏览器插件的支持,npapi的方案马上不可用. 当务之急要选择一个替代方案,最常用的就是扩展了.扩展程序提供了一套和本地程序交互的方案——“原生消息通信” 写 ...

  5. Delphi 解析系统环境变量

    // http://www.outofmemory.cn function ExpandEnvironment(const strValue: string): string; var chrResu ...

  6. Delphi经验总结(1)

    先人的DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername ...

  7. [转]Delphi 控件属性和事件

    常用[属性] Action:该属性是与组件关联的行为,允许应用程序集中响应用户命令 Anchors:与组件连接的窗体的位置点 Align:确定组件的对齐方式 AutoSize:确定组件是否自动调整其大 ...

  8. Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示

    Delphi 读取 c# webservice XML的base64编码图片字符串转化图片并显示 在 开发中遇到应用c#及asp.net的在的webservice 保存图片并以xml文件形式现实出来 ...

  9. copy other

    DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername/di ...

随机推荐

  1. JSONObject JSONArray json字符串 HashMap ArryList 在java开发中用到的数据结构

    1.JSONObject  长成这样的:   { "key1":value1, "key2":value2, "key3":value3} ...

  2. 【转】每天一个linux命令(45):free 命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/12/25/2831814.html free命令可以显示Linux系统中空闲的.已用的物理内存及swap ...

  3. 【转】每天一个linux命令(18):locate 命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/11/12/2765750.html locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其 ...

  4. LINQ TO SQL 中的join(转帖)

    http://www.cnblogs.com/ASPNET2008/archive/2008/12/21/1358152.html join对于喜欢写SQL的朋友来说还是比较实用,也比较容易接受的东西 ...

  5. bzoj1072排列

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1072 好像是这方面的裸题. 整除k 要想转移需要记录下 达到模k所有余数 的方案数. 为了生 ...

  6. 【python】class之子类

    父类: class AddrBookEntry(object): "address book entry class" def __init__(self, nm, ph): se ...

  7. JDBC进行简单的增删改查

    一.准备工作(一):MySQL安装配置和基础学习 二.准备工作(二):下载数据库对应的jar包并导入 三.JDBC基本操作 (1)定义记录的类(可选) (2)连接的获取 (3)insert (4)up ...

  8. 进程表/文件表/inode/vnode

    一般我们讲,都说进程有文件描述符表,文件描述符表中的指针指向某个inode,这中间省略了file,dentry对象,对准确理解VFS结构无益,本文结合网络所查,并根据APUE8.3和LKD13.11章 ...

  9. Bluez相关的各种tools的使用

    7.1        Bccmd Bccmd是用来和CSR的芯片进行BCCMD(Bluecore command protocol)通讯的一个工具.BCCMD并非蓝牙协议栈的标准,而是CSR芯片的专属 ...

  10. java 管道流PipedInputStream,PipedInputStream和随机访问文件 RandomAccessFile

    http://blog.csdn.net/zlp1992/article/details/50298195   给个链接自己去看吧.网上资料不是很多,而且自己也不想写了 RandomAccessFil ...