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. UltraEdit常用设置及快捷键

    = 关闭自动加载上次文件的方法,操作方法如下:首先,要打开UltraEdit,然后点击经[高级]-[配置],找到[文件处理]-[加载],把[重新载入先前在启动时打开的文件]勾去掉,并确定就可以了. 附 ...

  2. 产品思维&技术思维&工程思维

    产品思维 产品思维的起源是用户(或客户)价值.用户价值是通过技术手段以产品或服务的形态去解决用户的痛点,或带去爽点.毫无疑问,工程师在日常工作中应时刻关注并理清自己的工作与用户(或客户)价值的联系,并 ...

  3. 【转】每天一个linux命令(4):mkdir命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/10/25/2738271.html linux mkdir 命令用来创建指定的名称的目录,要求创建目录的 ...

  4. Oracle 实例恢复

    -======================= -- Oracle 实例恢复 --======================= 一.Oracle实例失败 Oracle实例失败多为实例非一致性关闭所 ...

  5. Servlet 实现网页计数器

    创建CounterSerlet, 使用getServletContext,ServletContext 从request.getSession().getServletContext();获得 @We ...

  6. vmware 安装 ios 苹果系统

    我用的系统是win10... 一.所需软件: 1.下载并安装VMware Workstation Pro 12 密码:7ybc和序列号 密码是:bwm0 2.下载unlocker 203(for OS ...

  7. 大快DKhadoop开发环境安装常见问题与解决方案

    2018年度国内大数据公司排名50强本月初榜单发布,榜单上看到大快搜索跻身50强,再看看他们做的DKHadoop发行版,的确还是蛮厉害的吧!最起码这款DKHadoop用起来确实在易用性方面要更好!Dk ...

  8. ML(3.2): NavieBayes R_kalR

    ML3.1 介绍e1071包实施朴素贝叶斯分类的函数,本例使用klaR包中的NaiveBayes函数,因为该函数较之前者增加了两个功能,一个是可以输入先验概率,另一个是在正态分布基础上增加了核平滑密度 ...

  9. 【python】python性能分析--待完善

    http://www.oschina.net/translate/python-performance-analysis http://blog.csdn.net/gzlaiyonghao/artic ...

  10. 快速接入PHP微信支付

    微信支付是微信开发中坑最多的一个功能,本文旨在帮助有开发基础的人快速接入微信支付,如果要详细了解微信支付,请看微信支付的开发文档. 再说把开发文档搬到这里来就没必要了.想要快速跑通微信支付的可以继续查 ...